mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-02 17:31:14 -05:00
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.
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
"""empty message
|
"""empty message
|
||||||
|
|
||||||
Revision ID: set_notifications_international
|
Revision ID: 0082_set_international
|
||||||
Revises: 0080_fix_rate_start_date
|
Revises: 0080_fix_rate_start_date
|
||||||
Create Date: 2017-05-05 15:26:34.621670
|
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.
|
# revision identifiers, used by Alembic.
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
revision = 'set_notifications_international'
|
revision = '0082_set_international'
|
||||||
down_revision = '0080_fix_rate_start_date'
|
down_revision = '0080_fix_rate_start_date'
|
||||||
|
|
||||||
from alembic import op
|
from alembic import op
|
||||||
@@ -19,14 +19,17 @@ import sqlalchemy as sa
|
|||||||
def upgrade():
|
def upgrade():
|
||||||
conn = op.get_bind()
|
conn = op.get_bind()
|
||||||
start = datetime.utcnow()
|
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)
|
results = conn.execute(all_notifications)
|
||||||
res = results.fetchall()
|
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:
|
while len(res) > 0:
|
||||||
conn.execute("update notifications set international = False where id in ({})".format(all_notifications))
|
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.execute("update notification_history set international = False where id in ({})".format(all_notifications))
|
||||||
conn.commit()
|
|
||||||
results = conn.execute(all_notifications)
|
results = conn.execute(all_notifications)
|
||||||
res = results.fetchall()
|
res = results.fetchall()
|
||||||
end = datetime.utcnow()
|
end = datetime.utcnow()
|
||||||
Reference in New Issue
Block a user