"""added pipeline_type, task_type

Revision ID: f0485471fbe6
Revises: 00fddd34b7e1
Create Date: 2016-06-05 12:11:10.255550

"""

# revision identifiers, used by Alembic.
revision = 'f0485471fbe6'
down_revision = '00fddd34b7e1'

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('task_types',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('method', sa.String(length=256), nullable=True),
    sa.Column('trf_template', sa.String(length=1024), nullable=True),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('pipeline_types',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('name', sa.String(length=256), nullable=True),
    sa.Column('init_tasktype_id', sa.Integer(), nullable=True),
    sa.Column('pre_tasktype_id', sa.Integer(), nullable=True),
    sa.Column('split_tasktype_id', sa.Integer(), nullable=True),
    sa.Column('prun_tasktype_id', sa.Integer(), nullable=True),
    sa.Column('merge_tasktype_id', sa.Integer(), nullable=True),
    sa.Column('post_tasktype_id', sa.Integer(), nullable=True),
    sa.Column('finish_tasktype_id', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['finish_tasktype_id'], ['task_types.id'], ),
    sa.ForeignKeyConstraint(['init_tasktype_id'], ['task_types.id'], ),
    sa.ForeignKeyConstraint(['merge_tasktype_id'], ['task_types.id'], ),
    sa.ForeignKeyConstraint(['post_tasktype_id'], ['task_types.id'], ),
    sa.ForeignKeyConstraint(['pre_tasktype_id'], ['task_types.id'], ),
    sa.ForeignKeyConstraint(['prun_tasktype_id'], ['task_types.id'], ),
    sa.ForeignKeyConstraint(['split_tasktype_id'], ['task_types.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.add_column(u'pipelines', sa.Column('current_state', sa.String(length=256), nullable=True))
    op.add_column(u'pipelines', sa.Column('finish_task', sa.Integer(), nullable=True))
    op.add_column(u'pipelines', sa.Column('init_task', sa.Integer(), nullable=True))
    op.add_column(u'pipelines', sa.Column('merge_task', sa.Integer(), nullable=True))
    op.add_column(u'pipelines', sa.Column('owner_id', sa.Integer(), nullable=True))
    op.add_column(u'pipelines', sa.Column('post_task', sa.Integer(), nullable=True))
    op.add_column(u'pipelines', sa.Column('pre_task', sa.Integer(), nullable=True))
    op.add_column(u'pipelines', sa.Column('prun_task', sa.Integer(), nullable=True))
    op.add_column(u'pipelines', sa.Column('split_task', sa.Integer(), nullable=True))
    op.add_column(u'pipelines', sa.Column('tag', sa.String(length=256), nullable=True))
    op.add_column(u'pipelines', sa.Column('type', sa.Integer(), nullable=True))
    op.create_foreign_key(None, 'pipelines', 'tasks', ['merge_task'], ['id'])
    op.create_foreign_key(None, 'pipelines', 'tasks', ['post_task'], ['id'])
    op.create_foreign_key(None, 'pipelines', 'tasks', ['finish_task'], ['id'])
    op.create_foreign_key(None, 'pipelines', 'tasks', ['prun_task'], ['id'])
    op.create_foreign_key(None, 'pipelines', 'tasks', ['pre_task'], ['id'])
    op.create_foreign_key(None, 'pipelines', 'tasks', ['init_task'], ['id'])
    op.create_foreign_key(None, 'pipelines', 'pipeline_types', ['type'], ['id'])
    op.create_foreign_key(None, 'pipelines', 'users', ['owner_id'], ['id'])
    op.create_foreign_key(None, 'pipelines', 'tasks', ['split_task'], ['id'])
    op.add_column(u'tasks', sa.Column('task_type_id', sa.Integer(), nullable=True))
    op.drop_constraint(u'tasks_ibfk_2', 'tasks', type_='foreignkey')
    op.create_foreign_key(None, 'tasks', 'task_types', ['task_type_id'], ['id'])
    op.drop_column(u'tasks', 'pipeline_id')
    ### end Alembic commands ###


def downgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.add_column(u'tasks', sa.Column('pipeline_id', mysql.INTEGER(display_width=11), autoincrement=False, nullable=True))
    op.drop_constraint(None, 'tasks', type_='foreignkey')
    op.create_foreign_key(u'tasks_ibfk_2', 'tasks', 'pipelines', ['pipeline_id'], ['id'])
    op.drop_column(u'tasks', 'task_type_id')
    op.drop_constraint(None, 'pipelines', type_='foreignkey')
    op.drop_constraint(None, 'pipelines', type_='foreignkey')
    op.drop_constraint(None, 'pipelines', type_='foreignkey')
    op.drop_constraint(None, 'pipelines', type_='foreignkey')
    op.drop_constraint(None, 'pipelines', type_='foreignkey')
    op.drop_constraint(None, 'pipelines', type_='foreignkey')
    op.drop_constraint(None, 'pipelines', type_='foreignkey')
    op.drop_constraint(None, 'pipelines', type_='foreignkey')
    op.drop_constraint(None, 'pipelines', type_='foreignkey')
    op.drop_column(u'pipelines', 'type')
    op.drop_column(u'pipelines', 'tag')
    op.drop_column(u'pipelines', 'split_task')
    op.drop_column(u'pipelines', 'prun_task')
    op.drop_column(u'pipelines', 'pre_task')
    op.drop_column(u'pipelines', 'post_task')
    op.drop_column(u'pipelines', 'owner_id')
    op.drop_column(u'pipelines', 'merge_task')
    op.drop_column(u'pipelines', 'init_task')
    op.drop_column(u'pipelines', 'finish_task')
    op.drop_column(u'pipelines', 'current_state')
    op.drop_table('pipeline_types')
    op.drop_table('task_types')
    ### end Alembic commands ###