"""add_activity_value_groups Revision ID: be788af9004f Revises: 435069151379 Create Date: 2019-12-04 16:11:39.890403 """ from alembic import op import sqlalchemy as sa from migrations import utils # revision identifiers, used by Alembic. revision = 'be788af9004f' down_revision = '435069151379' branch_labels = None depends_on = None def upgrade(): bind = op.get_bind() # ### commands auto generated by Alembic - please adjust! ### op.create_table('ActivityTypeGroup', sa.Column('id', sa.SmallInteger(), nullable=False), sa.Column('name', sa.String(length=50), nullable=False), sa.PrimaryKeyConstraint('id', name=op.f('pk_ActivityTypeGroup')) ) op.add_column('ActivityTypeValue', sa.Column('group_id', sa.SmallInteger(), nullable=True)) op.create_foreign_key(op.f('fk_ActivityTypeValue_group_id_ActivityTypeGroup'), 'ActivityTypeValue', 'ActivityTypeGroup', ['group_id'], ['id']) utils.import_data("ActivityTypeGroup", "activity_type_groups.csv") bind.execute('''UPDATE "ActivityTypeValue" SET group_id = 1 WHERE id IN (54, 55, 56, 57, 58, 293)''') bind.execute('''UPDATE "ActivityTypeValue" SET group_id = 2 WHERE id IN (59, 60, 61)''') bind.execute('''UPDATE "ActivityTypeValue" SET group_id = 3 WHERE id IN (62, 63, 64)''') bind.execute('''UPDATE "ActivityTypeValue" SET group_id = 4 WHERE id IN (65, 66, 67)''') bind.execute('''UPDATE "ActivityTypeValue" SET group_id = 5 WHERE id BETWEEN 68 AND 72''') # ### end Alembic commands ### def downgrade(): # ### commands auto generated by Alembic - please adjust! ### op.drop_constraint(op.f('fk_ActivityTypeValue_group_id_ActivityTypeGroup'), 'ActivityTypeValue', type_='foreignkey') op.drop_column('ActivityTypeValue', 'group_id') op.drop_table('ActivityTypeGroup') # ### end Alembic commands ###