"""added pipeline_catalog logic

Revision ID: f7208a6fdec4
Revises: d809ee2de92e
Create Date: 2016-08-01 19:41:29.335590

"""

# revision identifiers, used by Alembic.
revision = 'f7208a6fdec4'
down_revision = 'd809ee2de92e'

from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import mysql

def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.create_table('pipeline_catalog',
    sa.Column('pipeline_type_id', sa.Integer(), nullable=False),
    sa.Column('current_task_type_id', sa.Integer(), nullable=True),
    sa.Column('next_task_type_id', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['current_task_type_id'], ['task_types.id'], ),
    sa.ForeignKeyConstraint(['next_task_type_id'], ['task_types.id'], ),
    sa.ForeignKeyConstraint(['pipeline_type_id'], ['pipeline_types.id'], ),
    sa.PrimaryKeyConstraint('pipeline_type_id')
    )
    op.drop_constraint(u'pipeline_types_ibfk_4', 'pipeline_types', type_='foreignkey')
    op.drop_constraint(u'pipeline_types_ibfk_7', 'pipeline_types', type_='foreignkey')
    op.drop_constraint(u'pipeline_types_ibfk_6', 'pipeline_types', type_='foreignkey')
    op.drop_constraint(u'pipeline_types_ibfk_5', 'pipeline_types', type_='foreignkey')
    op.drop_constraint(u'pipeline_types_ibfk_2', 'pipeline_types', type_='foreignkey')
    op.drop_constraint(u'pipeline_types_ibfk_3', 'pipeline_types', type_='foreignkey')
    op.drop_constraint(u'pipeline_types_ibfk_1', 'pipeline_types', type_='foreignkey')
    op.drop_column(u'pipeline_types', 'post_tasktype_id')
    op.drop_column(u'pipeline_types', 'prun_tasktype_id')
    op.drop_column(u'pipeline_types', 'split_tasktype_id')
    op.drop_column(u'pipeline_types', 'merge_tasktype_id')
    op.drop_column(u'pipeline_types', 'init_tasktype_id')
    op.drop_column(u'pipeline_types', 'finish_tasktype_id')
    op.drop_column(u'pipeline_types', 'pre_tasktype_id')
    op.add_column(u'pipelines', sa.Column('current_task_id', sa.Integer(), nullable=True))
    op.drop_constraint(u'pipelines_ibfk_14', 'pipelines', type_='foreignkey')
    op.drop_constraint(u'pipelines_ibfk_15', 'pipelines', type_='foreignkey')
    op.drop_constraint(u'pipelines_ibfk_12', 'pipelines', type_='foreignkey')
    op.drop_constraint(u'pipelines_ibfk_17', 'pipelines', type_='foreignkey')
    op.drop_constraint(u'pipelines_ibfk_11', 'pipelines', type_='foreignkey')
    op.drop_constraint(u'pipelines_ibfk_16', 'pipelines', type_='foreignkey')
    op.drop_constraint(u'pipelines_ibfk_13', 'pipelines', type_='foreignkey')
    op.create_foreign_key(None, 'pipelines', 'tasks', ['current_task_id'], ['id'])
    op.drop_column(u'pipelines', 'split_task_id')
    op.drop_column(u'pipelines', 'pre_task_id')
    op.drop_column(u'pipelines', 'name')
    op.drop_column(u'pipelines', 'current_state')
    op.drop_column(u'pipelines', 'merge_task_id')
    op.drop_column(u'pipelines', 'post_task_id')
    op.drop_column(u'pipelines', 'prun_task_id')
    op.drop_column(u'pipelines', 'init_task_id')
    op.drop_column(u'pipelines', 'finish_task_id')
    ### end Alembic commands ###


def downgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.add_column(u'pipelines', sa.Column('finish_task_id', mysql.INTEGER(display_width=11), autoincrement=False, nullable=True))
    op.add_column(u'pipelines', sa.Column('init_task_id', mysql.INTEGER(display_width=11), autoincrement=False, nullable=True))
    op.add_column(u'pipelines', sa.Column('prun_task_id', mysql.INTEGER(display_width=11), autoincrement=False, nullable=True))
    op.add_column(u'pipelines', sa.Column('post_task_id', mysql.INTEGER(display_width=11), autoincrement=False, nullable=True))
    op.add_column(u'pipelines', sa.Column('merge_task_id', mysql.INTEGER(display_width=11), autoincrement=False, nullable=True))
    op.add_column(u'pipelines', sa.Column('current_state', mysql.VARCHAR(length=256), nullable=True))
    op.add_column(u'pipelines', sa.Column('name', mysql.VARCHAR(length=256), nullable=True))
    op.add_column(u'pipelines', sa.Column('pre_task_id', mysql.INTEGER(display_width=11), autoincrement=False, nullable=True))
    op.add_column(u'pipelines', sa.Column('split_task_id', mysql.INTEGER(display_width=11), autoincrement=False, nullable=True))
    op.drop_constraint(None, 'pipelines', type_='foreignkey')
    op.create_foreign_key(u'pipelines_ibfk_13', 'pipelines', 'tasks', ['prun_task_id'], ['id'])
    op.create_foreign_key(u'pipelines_ibfk_16', 'pipelines', 'tasks', ['split_task_id'], ['id'])
    op.create_foreign_key(u'pipelines_ibfk_11', 'pipelines', 'tasks', ['init_task_id'], ['id'])
    op.create_foreign_key(u'pipelines_ibfk_17', 'pipelines', 'tasks', ['finish_task_id'], ['id'])
    op.create_foreign_key(u'pipelines_ibfk_12', 'pipelines', 'tasks', ['merge_task_id'], ['id'])
    op.create_foreign_key(u'pipelines_ibfk_15', 'pipelines', 'tasks', ['post_task_id'], ['id'])
    op.create_foreign_key(u'pipelines_ibfk_14', 'pipelines', 'tasks', ['pre_task_id'], ['id'])
    op.drop_column(u'pipelines', 'current_task_id')
    op.add_column(u'pipeline_types', sa.Column('pre_tasktype_id', mysql.INTEGER(display_width=11), autoincrement=False, nullable=True))
    op.add_column(u'pipeline_types', sa.Column('finish_tasktype_id', mysql.INTEGER(display_width=11), autoincrement=False, nullable=True))
    op.add_column(u'pipeline_types', sa.Column('init_tasktype_id', mysql.INTEGER(display_width=11), autoincrement=False, nullable=True))
    op.add_column(u'pipeline_types', sa.Column('merge_tasktype_id', mysql.INTEGER(display_width=11), autoincrement=False, nullable=True))
    op.add_column(u'pipeline_types', sa.Column('split_tasktype_id', mysql.INTEGER(display_width=11), autoincrement=False, nullable=True))
    op.add_column(u'pipeline_types', sa.Column('prun_tasktype_id', mysql.INTEGER(display_width=11), autoincrement=False, nullable=True))
    op.add_column(u'pipeline_types', sa.Column('post_tasktype_id', mysql.INTEGER(display_width=11), autoincrement=False, nullable=True))
    op.create_foreign_key(u'pipeline_types_ibfk_1', 'pipeline_types', 'task_types', ['finish_tasktype_id'], ['id'])
    op.create_foreign_key(u'pipeline_types_ibfk_3', 'pipeline_types', 'task_types', ['merge_tasktype_id'], ['id'])
    op.create_foreign_key(u'pipeline_types_ibfk_2', 'pipeline_types', 'task_types', ['init_tasktype_id'], ['id'])
    op.create_foreign_key(u'pipeline_types_ibfk_5', 'pipeline_types', 'task_types', ['pre_tasktype_id'], ['id'])
    op.create_foreign_key(u'pipeline_types_ibfk_6', 'pipeline_types', 'task_types', ['prun_tasktype_id'], ['id'])
    op.create_foreign_key(u'pipeline_types_ibfk_7', 'pipeline_types', 'task_types', ['split_tasktype_id'], ['id'])
    op.create_foreign_key(u'pipeline_types_ibfk_4', 'pipeline_types', 'task_types', ['post_tasktype_id'], ['id'])
    op.drop_table('pipeline_catalog')
    ### end Alembic commands ###