"""Add bounty_category table with many-to-many relationship

Revision ID: d263d4125e87
Revises: 189a2ac27a82
Create Date: 2021-03-13 23:48:56.029673

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = 'd263d4125e87'
down_revision = '189a2ac27a82'
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('bounty_categories',
    sa.Column('bounty_id', sa.Integer(), nullable=False),
    sa.Column('category_id', sa.Integer(), nullable=False),
    sa.ForeignKeyConstraint(['bounty_id'], ['bounty.bounty_id'], name=op.f('fk_bounty_categories_bounty_id_bounty')),
    sa.ForeignKeyConstraint(['category_id'], ['category.category_id'], name=op.f('fk_bounty_categories_category_id_category')),
    sa.PrimaryKeyConstraint('bounty_id', 'category_id', name=op.f('pk_bounty_categories'))
    )
    op.drop_constraint('fk_bounty_category_id_category', 'bounty', type_='foreignkey')
    op.drop_column('bounty', 'category_id')
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('bounty', sa.Column('category_id', sa.INTEGER(), autoincrement=False, nullable=True))
    op.create_foreign_key('fk_bounty_category_id_category', 'bounty', 'category', ['category_id'], ['category_id'])
    op.drop_table('bounty_categories')
    # ### end Alembic commands ###
