mirror of
https://github.com/GSA/notifications-api.git
synced 2026-09-07 07:28:24 -04:00
fix syntax errors in downgrade script
This commit is contained in:
@@ -83,27 +83,19 @@ def downgrade():
|
|||||||
''')
|
''')
|
||||||
# set to 'null' if there are no billable services so we don't get a syntax error in the update statement
|
# set to 'null' if there are no billable services so we don't get a syntax error in the update statement
|
||||||
service_ids = ','.join("'{}'".format(service.id) for service in billable_services) or 'null'
|
service_ids = ','.join("'{}'".format(service.id) for service in billable_services) or 'null'
|
||||||
billable_services = session.query(Service).filter(Service.research_mode == False).all()
|
|
||||||
|
|
||||||
# caveats:
|
# caveats:
|
||||||
# only approximates character counts - billable * 153 to get at least a decent ballpark
|
# only approximates character counts - billable * 153 to get at least a decent ballpark
|
||||||
# research mode messages assumed to be one message length
|
# research mode messages assumed to be one message length
|
||||||
update_statement = '''
|
update_statement = '''
|
||||||
UPDATE {table}
|
UPDATE {}
|
||||||
SET content_char_count = GREATEST(billable_units, 1) * 150
|
SET content_char_count = GREATEST(billable_units, 1) * 150
|
||||||
)
|
|
||||||
WHERE service_id in ({})
|
WHERE service_id in ({})
|
||||||
AND notification_type = 'sms'
|
AND notification_type = 'sms'
|
||||||
'''
|
'''
|
||||||
|
|
||||||
conn = op.get_bind()
|
conn = op.get_bind()
|
||||||
conn.execute(update_statement.format(
|
conn.execute(update_statement.format('notifications', service_ids))
|
||||||
'notifications',
|
conn.execute(update_statement.format('notification_history', service_ids))
|
||||||
services=','.join(repr(str(service.id)) for service in billable_services)
|
|
||||||
))
|
|
||||||
conn.execute(update_statement.format(
|
|
||||||
'notification_history',
|
|
||||||
services=','.join(repr(str(service.id)) for service in billable_services)
|
|
||||||
))
|
|
||||||
op.drop_column('notifications', 'billable_units')
|
op.drop_column('notifications', 'billable_units')
|
||||||
op.drop_column('notification_history', 'billable_units')
|
op.drop_column('notification_history', 'billable_units')
|
||||||
|
|||||||
Reference in New Issue
Block a user