Switch web hook migration script to fully use the alembic context and connection
This commit is contained in:
parent
a44345338d
commit
2c3fe2e60f
1 changed files with 13 additions and 11 deletions
|
@ -11,19 +11,21 @@ Hand Edited By Joseph Schorr
|
||||||
revision = '47670cbeced'
|
revision = '47670cbeced'
|
||||||
down_revision = '325a4d7c79d9'
|
down_revision = '325a4d7c79d9'
|
||||||
|
|
||||||
from alembic import op
|
from alembic import op, context
|
||||||
import sqlalchemy as sa
|
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():
|
def upgrade():
|
||||||
event_id = list(db.execute_sql('Select id From ExternalNotificationEvent Where name="repo_push" Limit 1', ()))[0][0]
|
conn = op.get_bind()
|
||||||
method_id = list(db.execute_sql('Select id From ExternalNotificationMethod Where name="webhook" Limit 1', ()))[0][0]
|
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')
|
||||||
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.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():
|
def downgrade():
|
||||||
event_id = list(db.execute_sql('Select id From ExternalNotificationEvent Where name="repo_push" Limit 1', ()))[0][0]
|
conn = op.get_bind()
|
||||||
method_id = list(db.execute_sql('Select id From ExternalNotificationMethod Where name="webhook" Limit 1', ()))[0][0]
|
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')
|
||||||
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.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))
|
||||||
|
|
Reference in a new issue