fix syntax errors in downgrade script

This commit is contained in:
Leo Hemsted
2016-08-04 12:00:26 +01:00
parent 143cfb526c
commit d86af3ce83

View File

@@ -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')