From 2c3fe2e60f2025be9c1fc40660b2b594b4165572 Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Fri, 1 Aug 2014 13:37:27 -0400 Subject: [PATCH] Switch web hook migration script to fully use the alembic context and connection --- ...670cbeced_migrate_existing_webhooks_to_.py | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/data/migrations/versions/47670cbeced_migrate_existing_webhooks_to_.py b/data/migrations/versions/47670cbeced_migrate_existing_webhooks_to_.py index 92ce959e1..cf50bd737 100644 --- a/data/migrations/versions/47670cbeced_migrate_existing_webhooks_to_.py +++ b/data/migrations/versions/47670cbeced_migrate_existing_webhooks_to_.py @@ -11,19 +11,21 @@ Hand Edited By Joseph Schorr revision = '47670cbeced' down_revision = '325a4d7c79d9' -from alembic import op +from alembic import op, context import sqlalchemy as sa -from data.database import * -from app import app + +def get_id(query): + conn = op.get_bind() + return list(conn.execute(query, ()).fetchall())[0][0] def upgrade(): - event_id = list(db.execute_sql('Select id From ExternalNotificationEvent Where name="repo_push" Limit 1', ()))[0][0] - method_id = list(db.execute_sql('Select id From ExternalNotificationMethod Where name="webhook" Limit 1', ()))[0][0] - - db.execute_sql('Insert Into RepositoryNotification (uuid, repository_id, event_id, method_id, config_json) Select public_id, repository_id, %s, %s, parameters FROM Webhook' % (event_id, method_id)) + conn = op.get_bind() + event_id = get_id('Select id From ExternalNotificationEvent Where name="repo_push" Limit 1') + method_id = get_id('Select id From ExternalNotificationMethod Where name="webhook" Limit 1') + conn.execute('Insert Into RepositoryNotification (uuid, repository_id, event_id, method_id, config_json) Select public_id, repository_id, %s, %s, parameters FROM Webhook' % (event_id, method_id)) def downgrade(): - event_id = list(db.execute_sql('Select id From ExternalNotificationEvent Where name="repo_push" Limit 1', ()))[0][0] - method_id = list(db.execute_sql('Select id From ExternalNotificationMethod Where name="webhook" Limit 1', ()))[0][0] - - db.execute_sql('Insert Into Webhook (public_id, repository_id, parameters) Select uuid, repository_id, config_json FROM RepositoryNotification Where event_id=%s And method_id=%s' % (event_id, method_id)) + conn = op.get_bind() + event_id = get_id('Select id From ExternalNotificationEvent Where name="repo_push" Limit 1') + method_id = get_id('Select id From ExternalNotificationMethod Where name="webhook" Limit 1') + conn.execute('Insert Into Webhook (public_id, repository_id, parameters) Select uuid, repository_id, config_json FROM RepositoryNotification Where event_id=%s And method_id=%s' % (event_id, method_id))