"""improve relations for threads and comments

Revision ID: e3b140752719
Revises: 794d44c2bef8
Create Date: 2019-08-24 19:09:46.981771

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = 'e3b140752719'
down_revision = '794d44c2bef8'
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('thread', sa.Column('top_comment_id', sa.Integer(), nullable=True))
    op.drop_constraint('thread_top_comment_fkey', 'thread', type_='foreignkey')
    op.create_foreign_key(None, 'thread', 'comment', ['top_comment_id'], ['id'])
    op.drop_column('thread', 'top_comment')
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('thread', sa.Column('top_comment', sa.INTEGER(), autoincrement=False, nullable=True))
    op.drop_constraint(None, 'thread', type_='foreignkey')
    op.create_foreign_key('thread_top_comment_fkey', 'thread', 'comment', ['top_comment'], ['id'])
    op.drop_column('thread', 'top_comment_id')
    # ### end Alembic commands ###
