From 35136704086b5ffa43e5b9d2b2ac88b85f43c167 Mon Sep 17 00:00:00 2001 From: Rebecca Law Date: Mon, 8 May 2017 16:40:56 +0100 Subject: [PATCH] Script to update the international flag in the notifications and notification_history tables. This script may move where it is not run on db migration but as a one-off script from a server command. --- .../set_notifications_international.py | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 migrations/versions/set_notifications_international.py diff --git a/migrations/versions/set_notifications_international.py b/migrations/versions/set_notifications_international.py new file mode 100644 index 000000000..e476fae4e --- /dev/null +++ b/migrations/versions/set_notifications_international.py @@ -0,0 +1,37 @@ +"""empty message + +Revision ID: set_notifications_international +Revises: 0080_fix_rate_start_date +Create Date: 2017-05-05 15:26:34.621670 + +""" + +# revision identifiers, used by Alembic. +from datetime import datetime + +revision = 'set_notifications_international' +down_revision = '0080_fix_rate_start_date' + +from alembic import op +import sqlalchemy as sa + + +def upgrade(): + conn = op.get_bind() + start = datetime.utcnow() + all_notifications = "select id from notifications where international is null limit 1000" + + results = conn.execute(all_notifications) + res = results.fetchall() + while len(res) > 0: + conn.execute("update notifications set international = False where id in ({})".format(all_notifications)) + conn.execute("update notification_history set international = False where id in ({})".format(all_notifications)) + conn.commit() + results = conn.execute(all_notifications) + res = results.fetchall() + end = datetime.utcnow() + print("Started at: {} ended at: {}".format(start, end)) + +def downgrade(): + # There is no way to downgrade this update. + pass \ No newline at end of file