"""Add FlowSession to FlowRun

Revision ID: 1ec0c12acd99
Revises: fc58844182fe
Create Date: 2019-08-29 22:48:54.839695

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '1ec0c12acd99'
down_revision = 'fc58844182fe'
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    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.create_foreign_key(None, 'flow_run', 'flow_session', ['flow_session_id'], ['id'])
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_constraint(None, 'flow_run', type_='foreignkey')
    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')
    # ### end Alembic commands ###
