Blame alembic/versions/01e58ee9eccb_adjust_constraints_on_pull_request_flags.py

Pierre-Yves Chibon dc4c19
"""Adjust constraints on pull_request_flags
Pierre-Yves Chibon dc4c19
Pierre-Yves Chibon dc4c19
Revision ID: 01e58ee9eccb
Pierre-Yves Chibon dc4c19
Revises: 6119fbbcc8e9
Pierre-Yves Chibon dc4c19
Create Date: 2017-11-16 16:50:47.278252
Pierre-Yves Chibon dc4c19
Pierre-Yves Chibon dc4c19
"""
Pierre-Yves Chibon dc4c19
Pierre-Yves Chibon dc4c19
from alembic import op
Pierre-Yves Chibon dc4c19
import sqlalchemy as sa
Pierre-Yves Chibon dc4c19
Pierre-Yves Chibon dc4c19
Pierre-Yves Chibon dc4c19
# revision identifiers, used by Alembic.
Pierre-Yves Chibon dc4c19
revision = '01e58ee9eccb'
Pierre-Yves Chibon dc4c19
down_revision = '6119fbbcc8e9'
Pierre-Yves Chibon dc4c19
Pierre-Yves Chibon dc4c19
Pierre-Yves Chibon dc4c19
def upgrade():
Pierre-Yves Chibon dc4c19
    """ Remove the unique constraints on UID in pull_request_flags and make
Pierre-Yves Chibon dc4c19
    it a composite unique constraint on UID + pull_request_uid.
Pierre-Yves Chibon dc4c19
    """
Pierre-Yves Chibon dc4c19
    # alter the constraints
Pierre-Yves Chibon dc4c19
    op.drop_constraint('pull_request_flags_uid_key', 'pull_request_flags')
Pierre-Yves Chibon dc4c19
    op.create_unique_constraint(
Pierre-Yves Chibon dc4c19
            "pull_request_flags_uid_pull_request_uid_key",
Pierre-Yves Chibon dc4c19
            'pull_request_flags',
Pierre-Yves Chibon dc4c19
            ["uid", "pull_request_uid"]
Pierre-Yves Chibon dc4c19
    )
Pierre-Yves Chibon dc4c19
Pierre-Yves Chibon dc4c19
Pierre-Yves Chibon dc4c19
def downgrade():
Pierre-Yves Chibon dc4c19
    """ Remove the composite unique constraints on UID + pull_request_uid
Pierre-Yves Chibon dc4c19
    in pull_request_flags and make it an unique constraint on UID .
Pierre-Yves Chibon dc4c19
    """
Pierre-Yves Chibon dc4c19
    op.drop_constraint(
Pierre-Yves Chibon dc4c19
        'pull_request_flags_uid_pull_request_uid_key',
Pierre-Yves Chibon dc4c19
        'pull_request_flags')
Pierre-Yves Chibon dc4c19
    op.create_unique_constraint(
Pierre-Yves Chibon dc4c19
            "pull_request_flags_uid_key",
Pierre-Yves Chibon dc4c19
            'pull_request_flags',
Pierre-Yves Chibon dc4c19
            ["uid"]
Pierre-Yves Chibon dc4c19
    )