This repository has been archived on 2020-03-24. You can view files and clone it, but cannot push or open issues or pull requests.
quay/data/migrations/versions/47670cbeced_migrate_existing_webhooks_to_.py

32 lines
1.3 KiB
Python
Raw Normal View History

"""Migrate existing webhooks to notifications.
Revision ID: 47670cbeced
Revises: 325a4d7c79d9
Create Date: 2014-07-31 13:49:38.332807
Hand Edited By Joseph Schorr
"""
# revision identifiers, used by Alembic.
revision = '47670cbeced'
down_revision = '325a4d7c79d9'
from alembic import op, context
import sqlalchemy as sa
def get_id(query):
conn = op.get_bind()
return list(conn.execute(query, ()).fetchall())[0][0]
def upgrade(tables):
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(tables):
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))