From d86af3ce83d78676d043655b9364300d3052c590 Mon Sep 17 00:00:00 2001 From: Leo Hemsted Date: Thu, 4 Aug 2016 12:00:26 +0100 Subject: [PATCH] fix syntax errors in downgrade script --- migrations/versions/0045_billable_units.py | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/migrations/versions/0045_billable_units.py b/migrations/versions/0045_billable_units.py index ed1d9d262..ab24ea7d6 100644 --- a/migrations/versions/0045_billable_units.py +++ b/migrations/versions/0045_billable_units.py @@ -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 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: # only approximates character counts - billable * 153 to get at least a decent ballpark # research mode messages assumed to be one message length update_statement = ''' - UPDATE {table} + UPDATE {} SET content_char_count = GREATEST(billable_units, 1) * 150 - ) WHERE service_id in ({}) AND notification_type = 'sms' ''' conn = op.get_bind() - conn.execute(update_statement.format( - 'notifications', - 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) - )) + conn.execute(update_statement.format('notifications', service_ids)) + conn.execute(update_statement.format('notification_history', service_ids)) op.drop_column('notifications', 'billable_units') op.drop_column('notification_history', 'billable_units')