"""add_new_placement Revision ID: 83e45837b572 Revises: c294b1ff8d05 Create Date: 2022-02-07 12:58:19.423896 """ from alembic import op # revision identifiers, used by Alembic. revision = '83e45837b572' down_revision = 'c294b1ff8d05' branch_labels = None depends_on = None new_placement = {"name": "Reels", "platform": "Instagram"} def upgrade(): # ### commands auto generated by Alembic - please adjust! ### bind = op.get_bind() platform = new_placement["platform"] platform_id = bind.execute( f'''SELECT id from "CampaignPlatforms" WHERE name = '{platform}' ''').fetchone()[0] resp = bind.execute( f'''INSERT INTO "CampaignPlacements" (name) VALUES ('{new_placement["name"]}') RETURNING id''' ) placement_id = resp.first()[0] bind.execute( f'''INSERT INTO "CampaignPlatformPlacements" VALUES ({platform_id}, {placement_id})''' ) # ### end Alembic commands ### def downgrade(): bind = op.get_bind() platform_id = bind.execute( f'''SELECT id from "CampaignPlatforms" WHERE name = '{new_placement["platform"]}' ''' ).fetchone()[0] placement_id = bind.execute( f'''SELECT id from "CampaignPlacements" WHERE name = '{new_placement["name"]}' ''' ).fetchone()[0] bind.execute( f'''DELETE FROM "CampaignPlatformPlacements" WHERE platform_id = {platform_id} AND placement_id = {placement_id} ''' ) bind.execute( f'''DELETE FROM "CampaignPlacements" WHERE id = {placement_id} ''' ) # ### end Alembic commands ###