"""purchase_orders_mapping Revision ID: 44a2210059c3 Revises: 5cc9b7423be5 Create Date: 2021-05-12 09:49:41.688931 """ from alembic import op import sqlalchemy as sa from migrations.fixtures import prs_po_map from migrations import utils # revision identifiers, used by Alembic. revision = '44a2210059c3' down_revision = '5cc9b7423be5' branch_labels = None depends_on = None new_moment_type = { "id" : 43, "name": "Live Performance", "group_id": 6 # Appearances } def get_table(bind, name): meta = sa.MetaData(bind=bind) meta.reflect() return meta.tables[name] def upgrade(): bind = op.get_bind() artist_moment_type_table = get_table(bind, "ArtistMomentType") campaign_type_value_table = get_table(bind, "CampaignTypeValue") bind.execute(artist_moment_type_table.insert().values(**new_moment_type)) bind.execute(campaign_type_value_table.update().where(campaign_type_value_table.c.id == 22).values(group_id=3)) utils.import_data_json("RawPRSPurchaseOrdersMap", prs_po_map.rca_data) def downgrade(): bind = op.get_bind() bind.execute('''DELETE FROM "ArtistMomentType" WHERE id = 43;''') bind.execute('''TRUNCATE "RawPRSPurchaseOrdersMap" RESTART IDENTITY;''') utils.import_data_json("RawPRSPurchaseOrdersMap", prs_po_map.data) campaign_type_value_table = get_table(bind, "CampaignTypeValue") bind.execute(campaign_type_value_table.update().where(campaign_type_value_table.c.id == 22).values(group_id=2))