"""add_gras_projects_to_recent_search_item Revision ID: 4d2379fbeff5 Revises: d55cd0c624a5 Create Date: 2021-03-25 14:59:45.180748 """ from alembic import op import sqlalchemy as sa # revision identifiers, used by Alembic. revision = '4d2379fbeff5' down_revision = '1acc5379edb5' branch_labels = None depends_on = None def upgrade(): op.add_column('RecentSearchItem', sa.Column('gras_project_id', sa.BigInteger(), nullable=True)) op.create_foreign_key(op.f('fk_RecentSearchItem_gras_project_id_GRASProject'), 'RecentSearchItem', 'GRASProject', ['gras_project_id'], ['id']) op.create_unique_constraint('uq_RecentSearchItem_gras_project_id_user_id', 'RecentSearchItem', ['gras_project_id','user_id']) op.drop_constraint(op.f('ck_RecentSearchItem_ck_RecentSearchItem_type'), 'RecentSearchItem', type_="check") op.create_check_constraint(op.f("ck_RecentSearchItem_ck_RecentSearchItem_type"), "RecentSearchItem", f"(artist_id is not null AND type = 0) OR (project_id is not null AND type = 1) OR (campaign_id is not null AND type = 2) OR (gras_project_id is not null AND type = 3)") def downgrade(): bind = op.get_bind() bind.execute('''DELETE FROM "RecentSearchItem" WHERE type=3''') op.drop_constraint(op.f('ck_RecentSearchItem_ck_RecentSearchItem_type'), 'RecentSearchItem', type_="check") op.create_check_constraint(op.f("ck_RecentSearchItem_ck_RecentSearchItem_type"), "RecentSearchItem", f"(artist_id is not null AND type = 0) OR (project_id is not null AND type = 1) OR (campaign_id is not null AND type = 2)") op.drop_column("RecentSearchItem", "gras_project_id")