mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-01 23:55:58 -05:00
Create a server command to run custom db scripts.
This commit is contained in:
@@ -2,7 +2,10 @@ import uuid
|
||||
from datetime import datetime
|
||||
from decimal import Decimal
|
||||
from flask.ext.script import Command, Manager, Option
|
||||
from app.models import (PROVIDERS, Service, User)
|
||||
|
||||
|
||||
from app import db
|
||||
from app.models import (PROVIDERS, Service, User, NotificationHistory)
|
||||
from app.dao.services_dao import (
|
||||
delete_service_and_all_associated_db_objects,
|
||||
dao_fetch_all_services_by_user
|
||||
@@ -60,3 +63,19 @@ class PurgeFunctionalTestDataCommand(Command):
|
||||
else:
|
||||
delete_user_verify_codes(usr)
|
||||
delete_model_user(usr)
|
||||
|
||||
|
||||
class CustomDbScript(Command):
|
||||
def run(self):
|
||||
self.update_notification_international_flag()
|
||||
|
||||
def update_notification_international_flag(self):
|
||||
# 250,000 rows takes 30 seconds to update.
|
||||
subq = "select id from notification_history where international is null limit 250000"
|
||||
update = "update notification_history set international = False where id in ({})".format(subq)
|
||||
result = db.session.execute(subq).fetchall()
|
||||
while len(result) > 0:
|
||||
db.session.execute(update)
|
||||
print('commit 10000 updates at {}'.format(datetime.utcnow()))
|
||||
db.session.commit()
|
||||
result = db.session.execute(subq).fetchall()
|
||||
|
||||
Reference in New Issue
Block a user