From f0a5851d73b76f3a59e2c15d7498ab074239eeaa Mon Sep 17 00:00:00 2001 From: Rebecca Law Date: Wed, 10 May 2017 14:02:11 +0100 Subject: [PATCH] The script updates 10,000 rows at a time, committing after each one. This should limit the distrubtion to the environment as only the rows being updated will be locked. It is likely those rows will not have a conflicting update at the same time since the records are older than 3 days. --- ...ons_international.py => 0082_set_international.py} | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) rename migrations/versions/{set_notifications_international.py => 0082_set_international.py} (69%) diff --git a/migrations/versions/set_notifications_international.py b/migrations/versions/0082_set_international.py similarity index 69% rename from migrations/versions/set_notifications_international.py rename to migrations/versions/0082_set_international.py index e476fae4e..97d3f5881 100644 --- a/migrations/versions/set_notifications_international.py +++ b/migrations/versions/0082_set_international.py @@ -1,6 +1,6 @@ """empty message -Revision ID: set_notifications_international +Revision ID: 0082_set_international Revises: 0080_fix_rate_start_date Create Date: 2017-05-05 15:26:34.621670 @@ -9,7 +9,7 @@ Create Date: 2017-05-05 15:26:34.621670 # revision identifiers, used by Alembic. from datetime import datetime -revision = 'set_notifications_international' +revision = '0082_set_international' down_revision = '0080_fix_rate_start_date' from alembic import op @@ -19,14 +19,17 @@ 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" + all_notifications = "select id from notification_history where international is null limit 10000" results = conn.execute(all_notifications) res = results.fetchall() + + 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)) + 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()