mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-10 07:12:20 -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 datetime import datetime
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
from flask.ext.script import Command, Manager, Option
|
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 (
|
from app.dao.services_dao import (
|
||||||
delete_service_and_all_associated_db_objects,
|
delete_service_and_all_associated_db_objects,
|
||||||
dao_fetch_all_services_by_user
|
dao_fetch_all_services_by_user
|
||||||
@@ -60,3 +63,19 @@ class PurgeFunctionalTestDataCommand(Command):
|
|||||||
else:
|
else:
|
||||||
delete_user_verify_codes(usr)
|
delete_user_verify_codes(usr)
|
||||||
delete_model_user(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()
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ migrate = Migrate(application, db)
|
|||||||
manager.add_command('db', MigrateCommand)
|
manager.add_command('db', MigrateCommand)
|
||||||
manager.add_command('create_provider_rate', commands.CreateProviderRateCommand)
|
manager.add_command('create_provider_rate', commands.CreateProviderRateCommand)
|
||||||
manager.add_command('purge_functional_test_data', commands.PurgeFunctionalTestDataCommand)
|
manager.add_command('purge_functional_test_data', commands.PurgeFunctionalTestDataCommand)
|
||||||
|
manager.add_command('custom_db_script', commands.CustomDbScript)
|
||||||
|
|
||||||
|
|
||||||
@manager.command
|
@manager.command
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ manager = Manager(application)
|
|||||||
migrate = Migrate(application, db)
|
migrate = Migrate(application, db)
|
||||||
manager.add_command('db', MigrateCommand)
|
manager.add_command('db', MigrateCommand)
|
||||||
manager.add_command('purge_functional_test_data', commands.PurgeFunctionalTestDataCommand)
|
manager.add_command('purge_functional_test_data', commands.PurgeFunctionalTestDataCommand)
|
||||||
|
manager.add_command('custom_db_script', commands.CustomDbScript)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
manager.run()
|
manager.run()
|
||||||
|
|||||||
Reference in New Issue
Block a user