mirror of
https://github.com/GSA/notifications-api.git
synced 2026-01-11 13:11:17 -05:00
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.
This commit is contained in:
37
migrations/versions/set_notifications_international.py
Normal file
37
migrations/versions/set_notifications_international.py
Normal file
@@ -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
|
||||
Reference in New Issue
Block a user