"""Introduce FlowSession entity

Revision ID: 1fdddb843025
Revises: 5a540bec1090
Create Date: 2019-08-29 18:45:16.483667

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '1fdddb843025'
down_revision = '5a540bec1090'
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('flow', sa.Column('current_session_id', sa.Integer(), nullable=True))
    op.create_foreign_key(None, 'flow', 'flow_session', ['current_session_id'], ['id'])
    op.drop_column('flow', 'description')
    op.add_column('flow_run', sa.Column('flow_session_id', sa.Integer(), nullable=False))
    op.drop_constraint('flow_run_key_flow_id_key', 'flow_run', type_='unique')
    op.create_unique_constraint(None, 'flow_run', ['key', 'flow_session_id'])
    op.drop_constraint('flow_run_flow_id_fkey', 'flow_run', type_='foreignkey')
    op.create_foreign_key(None, 'flow_run', 'flow_session', ['flow_session_id'], ['id'])
    op.drop_column('flow_run', 'flow_id')
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('flow_run', sa.Column('flow_id', sa.INTEGER(), autoincrement=False, nullable=False))
    op.drop_constraint(None, 'flow_run', type_='foreignkey')
    op.create_foreign_key('flow_run_flow_id_fkey', 'flow_run', 'flow', ['flow_id'], ['id'])
    op.drop_constraint(None, 'flow_run', type_='unique')
    op.create_unique_constraint('flow_run_key_flow_id_key', 'flow_run', ['key', 'flow_id'])
    op.drop_column('flow_run', 'flow_session_id')
    op.add_column('flow', sa.Column('description', sa.VARCHAR(), autoincrement=False, nullable=True))
    op.drop_constraint(None, 'flow', type_='foreignkey')
    op.drop_column('flow', 'current_session_id')
    # ### end Alembic commands ###
