"""add_unique_constraint_external_id_to_user_table Revision ID: 1fc97d27e260 Revises: dd2ee98d45e4 Create Date: 2022-03-10 14:13:47.249024 """ from alembic import op import sqlalchemy as sa # revision identifiers, used by Alembic. revision = '1fc97d27e260' down_revision = 'dd2ee98d45e4' branch_labels = None depends_on = None def upgrade(): bind = op.get_bind() constraint_present = bind.execute(''' select constraint_name from information_schema.constraint_column_usage where table_name = 'User' and constraint_name = 'uq_User_external_id' ''').fetchone() if constraint_present is None: op.create_unique_constraint('uq_User_external_id', 'User', ['external_id']) constraint_present = bind.execute(''' select constraint_name from information_schema.constraint_column_usage where table_name = 'User' and constraint_name = 'uq_User_email' ''').fetchone() if constraint_present is None: op.create_unique_constraint('uq_User_email', 'User', ['email']) def downgrade(): op.drop_constraint(op.f('uq_User_external_id'), 'User', type_='unique') op.drop_constraint(op.f('uq_User_email'), 'User', type_='unique')