Blame alembic/versions/317a285e04a8_delete_hooks.py

Pierre-Yves Chibon ab59c1
"""Delete hooks
Pierre-Yves Chibon ab59c1
Pierre-Yves Chibon ab59c1
Revision ID: 317a285e04a8
Pierre-Yves Chibon ab59c1
Revises: 2aa7b3958bc5
Pierre-Yves Chibon ab59c1
Create Date: 2016-05-30 11:28:48.512577
Pierre-Yves Chibon ab59c1
Pierre-Yves Chibon ab59c1
"""
Pierre-Yves Chibon ab59c1
Pierre-Yves Chibon ab59c1
# revision identifiers, used by Alembic.
Pierre-Yves Chibon ab59c1
revision = '317a285e04a8'
Pierre-Yves Chibon ab59c1
down_revision = '2aa7b3958bc5'
Pierre-Yves Chibon ab59c1
Pierre-Yves Chibon ab59c1
from alembic import op
Pierre-Yves Chibon ab59c1
import sqlalchemy as sa
Pierre-Yves Chibon ab59c1
Pierre-Yves Chibon ab59c1
Pierre-Yves Chibon ab59c1
def upgrade():
Pierre-Yves Chibon ab59c1
    """ Alter the hooks table to update the foreign key to cascade on delete.
Pierre-Yves Chibon ab59c1
    """
Pierre-Yves Chibon ab59c1
Pierre-Yves Chibon ab59c1
    for table in [
Pierre-Yves Chibon ab59c1
            'hook_fedmsg', 'hook_irc', 'hook_mail',
Pierre-Yves Chibon ab59c1
            'hook_pagure_force_commit', 'hook_pagure', 'hook_pagure_requests',
Pierre-Yves Chibon ab59c1
            'hook_pagure_tickets', 'hook_pagure_unsigned_commit', 'hook_rtd',
Pierre-Yves Chibon ab59c1
            ]:
Pierre-Yves Chibon ab59c1
        op.drop_constraint(
Pierre-Yves Chibon ab59c1
            '%s_project_id_fkey' % table,
Pierre-Yves Chibon ab59c1
            table,
Pierre-Yves Chibon ab59c1
            type_='foreignkey')
Pierre-Yves Chibon ab59c1
        op. create_foreign_key(
Pierre-Yves Chibon ab59c1
            name='%s_project_id_fkey' % table,
Pierre-Yves Chibon ab59c1
            source_table=table,
Pierre-Yves Chibon ab59c1
            referent_table='projects',
Pierre-Yves Chibon ab59c1
            local_cols=['project_id'],
Pierre-Yves Chibon ab59c1
            remote_cols=['id'],
Pierre-Yves Chibon ab59c1
            onupdate='cascade',
Pierre-Yves Chibon ab59c1
            ondelete='cascade',
Pierre-Yves Chibon ab59c1
        )
Pierre-Yves Chibon ab59c1
Pierre-Yves Chibon ab59c1
    op.drop_constraint(
Pierre-Yves Chibon ab59c1
        'projects_groups_project_id_fkey',
Pierre-Yves Chibon ab59c1
        'projects_groups',
Pierre-Yves Chibon ab59c1
        type_='foreignkey')
Pierre-Yves Chibon ab59c1
    op. create_foreign_key(
Pierre-Yves Chibon ab59c1
        name='projects_groups_project_id_fkey',
Pierre-Yves Chibon ab59c1
        source_table='projects_groups',
Pierre-Yves Chibon ab59c1
        referent_table='projects',
Pierre-Yves Chibon ab59c1
        local_cols=['project_id'],
Pierre-Yves Chibon ab59c1
        remote_cols=['id'],
Pierre-Yves Chibon ab59c1
        onupdate='cascade',
Pierre-Yves Chibon ab59c1
        ondelete='cascade',
Pierre-Yves Chibon ab59c1
    )
Pierre-Yves Chibon ab59c1
Pierre-Yves Chibon ab59c1
Pierre-Yves Chibon ab59c1
Pierre-Yves Chibon ab59c1
def downgrade():
Pierre-Yves Chibon ab59c1
    """ Alter the hooks table to update the foreign key to undo the cascade
Pierre-Yves Chibon ab59c1
    on delete.
Pierre-Yves Chibon ab59c1
    """