<reponame>geka32team/moonshot-jam-2020-back<filename>migrations/versions/20201227_175743_aa46d0993e2e_move_bonuses_from_items_table_to_set_.py<gh_stars>0
"""Move bonuses from items table to set_types one.

Revision ID: aa46d0993e2e
Revises: 0612b1984ec8
Create Date: 2020-12-27 17:57:43.078696

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = 'aa46d0993e2e'
down_revision = '0612b1984ec8'
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    with op.batch_alter_table('items', schema=None) as batch_op:
        batch_op.drop_constraint('items_bonus_fullset_id', type_='foreignkey')
        batch_op.drop_constraint('items_bonus_2items_id', type_='foreignkey')
        batch_op.drop_column('bonus_fullset_id')
        batch_op.drop_column('bonus_2items_id')

    with op.batch_alter_table('set_types', schema=None) as batch_op:
        batch_op.add_column(sa.Column('bonus_2items_id',
                                      sa.Integer(), nullable=False))
        batch_op.add_column(sa.Column('bonus_fullset_id',
                                      sa.Integer(), nullable=False))
        batch_op.create_foreign_key('set_types_bonus_2items_id', 'bonuses',
                                    ['bonus_2items_id'], ['id'])
        batch_op.create_foreign_key('set_types_bonus_fullset_id', 'bonuses',
                                    ['bonus_fullset_id'], ['id'])

    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    with op.batch_alter_table('set_types', schema=None) as batch_op:
        batch_op.drop_constraint(
            'set_types_bonus_fullset_id', type_='foreignkey')
        batch_op.drop_constraint(
            'set_types_bonus_2items_id', type_='foreignkey')
        batch_op.drop_column('bonus_fullset_id')
        batch_op.drop_column('bonus_2items_id')

    with op.batch_alter_table('items', schema=None) as batch_op:
        batch_op.add_column(sa.Column('bonus_2items_id',
                                      sa.INTEGER(), autoincrement=False, nullable=False))
        batch_op.add_column(sa.Column('bonus_fullset_id',
                                      sa.INTEGER(), autoincrement=False, nullable=False))
        batch_op.create_foreign_key('items_bonus_2items_id', 'bonuses',
                                    ['bonus_2items_id'], ['id'])
        batch_op.create_foreign_key('items_bonus_fullset_id', 'bonuses',
                                    ['bonus_fullset_id'], ['id'])

    # ### end Alembic commands ###

"""Move bonuses from items table to set_types one.

Revision ID: aa46d0993e2e
Revises: 0612b1984ec8
Create Date: 2020-12-27 17:57:43.078696

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = 'aa46d0993e2e'
down_revision = '0612b1984ec8'
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    with op.batch_alter_table('items', schema=None) as batch_op:
        batch_op.drop_constraint('items_bonus_fullset_id', type_='foreignkey')
        batch_op.drop_constraint('items_bonus_2items_id', type_='foreignkey')
        batch_op.drop_column('bonus_fullset_id')
        batch_op.drop_column('bonus_2items_id')

    with op.batch_alter_table('set_types', schema=None) as batch_op:
        batch_op.add_column(sa.Column('bonus_2items_id',
                                      sa.Integer(), nullable=False))
        batch_op.add_column(sa.Column('bonus_fullset_id',
                                      sa.Integer(), nullable=False))
        batch_op.create_foreign_key('set_types_bonus_2items_id', 'bonuses',
                                    ['bonus_2items_id'], ['id'])
        batch_op.create_foreign_key('set_types_bonus_fullset_id', 'bonuses',
                                    ['bonus_fullset_id'], ['id'])

    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    with op.batch_alter_table('set_types', schema=None) as batch_op:
        batch_op.drop_constraint(
            'set_types_bonus_fullset_id', type_='foreignkey')
        batch_op.drop_constraint(
            'set_types_bonus_2items_id', type_='foreignkey')
        batch_op.drop_column('bonus_fullset_id')
        batch_op.drop_column('bonus_2items_id')

    with op.batch_alter_table('items', schema=None) as batch_op:
        batch_op.add_column(sa.Column('bonus_2items_id',
                                      sa.INTEGER(), autoincrement=False, nullable=False))
        batch_op.add_column(sa.Column('bonus_fullset_id',
                                      sa.INTEGER(), autoincrement=False, nullable=False))
        batch_op.create_foreign_key('items_bonus_2items_id', 'bonuses',
                                    ['bonus_2items_id'], ['id'])
        batch_op.create_foreign_key('items_bonus_fullset_id', 'bonuses',
                                    ['bonus_fullset_id'], ['id'])

    # ### end Alembic commands ###
Move bonuses from items table to set_types one.  Revision ID: aa46d0993e2e Revises: 0612b1984ec8 Create Date: 2020-12-27 17:57:43.078696 # revision identifiers, used by Alembic. # ### commands auto generated by Alembic - please adjust! ### # ### end Alembic commands ### # ### commands auto generated by Alembic - please adjust! ### # ### end Alembic commands ###