"""tag_and_topic

Revision ID: e36d919d0e93
Revises: fa4db43bbfa9
Create Date: 2019-10-28 22:58:11.345219

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = 'e36d919d0e93'
down_revision = 'fa4db43bbfa9'
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('tags',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('title', sa.String(length=64), nullable=True),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('topics',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('title', sa.Text(), nullable=True),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('post_tag_relations',
    sa.Column('post_id', sa.Integer(), nullable=True),
    sa.Column('tag_id', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['post_id'], ['tags.id'], ),
    sa.ForeignKeyConstraint(['tag_id'], ['posts.id'], )
    )
    op.add_column('posts', sa.Column('topic_id', sa.Integer(), nullable=True))
    op.create_foreign_key(None, 'posts', 'topics', ['topic_id'], ['id'])
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_constraint(None, 'posts', type_='foreignkey')
    op.drop_column('posts', 'topic_id')
    op.drop_table('post_tag_relations')
    op.drop_table('topics')
    op.drop_table('tags')
    # ### end Alembic commands ###
