"""
 Copyright (c) 2015 Michael Bright and Bamboo HR LLC

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.

adding indexes

Revision ID: 3da597dde134
Revises: 24054f4c1f76
Create Date: 2015-12-17 13:37:27.681085

"""

# revision identifiers, used by Alembic.
revision = '3da597dde134'
down_revision = '24054f4c1f76'
branch_labels = ()
depends_on = None

from alembic import op
import sqlalchemy as sa


def upgrade():
    if 'sqlite' != op.get_context().dialect.name:
        op.alter_column('actions', 'name',
                        existing_type=sa.VARCHAR(length=100),
                        nullable=False)

    ### commands auto generated by Alembic - please adjust! ###
    op.create_index(op.f('ix_action_instances_action_id'), 'action_instances', ['action_id'], unique=False)
    op.create_index(op.f('ix_action_instances_id'), 'action_instances', ['id'], unique=False)
    op.create_index(op.f('ix_action_instances_pipeline_instance_id'), 'action_instances', ['pipeline_instance_id'], unique=False)
    op.create_index(op.f('ix_action_instances_status_id'), 'action_instances', ['status_id'], unique=False)
    op.create_index(op.f('ix_action_instances_workflow_instance_id'), 'action_instances', ['workflow_instance_id'], unique=False)
    op.create_index(op.f('ix_actions_id'), 'actions', ['id'], unique=False)
    op.create_index(op.f('ix_actions_pipeline_id'), 'actions', ['pipeline_id'], unique=False)
    op.create_index(op.f('ix_actions_workflow_id'), 'actions', ['workflow_id'], unique=False)
    op.create_index(op.f('ix_pipeline_instances_id'), 'pipeline_instances', ['id'], unique=False)
    op.create_index(op.f('ix_pipeline_instances_pipeline_id'), 'pipeline_instances', ['pipeline_id'], unique=False)
    op.create_index(op.f('ix_pipeline_instances_status_id'), 'pipeline_instances', ['status_id'], unique=False)
    op.create_index(op.f('ix_pipeline_parameters_id'), 'pipeline_parameters', ['id'], unique=False)
    op.create_index(op.f('ix_pipeline_parameters_parameter'), 'pipeline_parameters', ['parameter'], unique=False)
    op.create_index(op.f('ix_pipeline_parameters_pipeline_instance_id'), 'pipeline_parameters', ['pipeline_instance_id'], unique=False)
    op.create_index(op.f('ix_pipeline_statistics_id'), 'pipeline_statistics', ['id'], unique=False)
    op.create_index(op.f('ix_pipeline_statistics_pipeline_instance_id'), 'pipeline_statistics', ['pipeline_instance_id'], unique=False)
    op.create_index(op.f('ix_pipeline_statistics_statistics_id'), 'pipeline_statistics', ['statistics_id'], unique=False)
    op.create_index(op.f('ix_pipelines_id'), 'pipelines', ['id'], unique=False)
    op.create_index(op.f('ix_qa_test_histories_action_instance_id'), 'qa_test_histories', ['action_instance_id'], unique=False)
    op.create_index(op.f('ix_qa_test_histories_id'), 'qa_test_histories', ['id'], unique=False)
    op.create_index(op.f('ix_qa_test_histories_pipeline_instance_id'), 'qa_test_histories', ['pipeline_instance_id'], unique=False)
    op.create_index(op.f('ix_qa_test_histories_status_id'), 'qa_test_histories', ['status_id'], unique=False)
    op.create_index(op.f('ix_qa_test_histories_test_id'), 'qa_test_histories', ['test_id'], unique=False)
    op.create_index(op.f('ix_qa_tests_id'), 'qa_tests', ['id'], unique=False)
    op.create_index(op.f('ix_stage_instances_id'), 'stage_instances', ['id'], unique=False)
    op.create_index(op.f('ix_stage_instances_pipeline_instance_id'), 'stage_instances', ['pipeline_instance_id'], unique=False)
    op.create_index(op.f('ix_stage_instances_stage_id'), 'stage_instances', ['stage_id'], unique=False)
    op.create_index(op.f('ix_stage_instances_status_id'), 'stage_instances', ['status_id'], unique=False)
    op.create_index(op.f('ix_stages_id'), 'stages', ['id'], unique=False)
    op.create_index(op.f('ix_stages_pipeline_id'), 'stages', ['pipeline_id'], unique=False)
    op.create_index(op.f('ix_statistics_id'), 'statistics', ['id'], unique=False)
    op.create_index(op.f('ix_statuses_id'), 'statuses', ['id'], unique=False)
    op.create_index(op.f('ix_statuses_type'), 'statuses', ['type'], unique=False)
    op.create_index(op.f('ix_workflow_instances_id'), 'workflow_instances', ['id'], unique=False)
    op.create_index(op.f('ix_workflow_instances_stage_instance_id'), 'workflow_instances', ['stage_instance_id'], unique=False)
    op.create_index(op.f('ix_workflow_instances_status_id'), 'workflow_instances', ['status_id'], unique=False)
    op.create_index(op.f('ix_workflow_instances_workflow_id'), 'workflow_instances', ['workflow_id'], unique=False)
    op.create_index(op.f('ix_workflows_id'), 'workflows', ['id'], unique=False)
    op.create_index(op.f('ix_workflows_stage_id'), 'workflows', ['stage_id'], unique=False)
    ### end Alembic commands ###


def downgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.drop_index(op.f('ix_workflows_stage_id'), table_name='workflows')
    op.drop_index(op.f('ix_workflows_id'), table_name='workflows')
    op.drop_index(op.f('ix_workflow_instances_workflow_id'), table_name='workflow_instances')
    op.drop_index(op.f('ix_workflow_instances_status_id'), table_name='workflow_instances')
    op.drop_index(op.f('ix_workflow_instances_stage_instance_id'), table_name='workflow_instances')
    op.drop_index(op.f('ix_workflow_instances_id'), table_name='workflow_instances')
    op.drop_index(op.f('ix_statuses_type'), table_name='statuses')
    op.drop_index(op.f('ix_statuses_id'), table_name='statuses')
    op.drop_index(op.f('ix_statistics_id'), table_name='statistics')
    op.drop_index(op.f('ix_stages_pipeline_id'), table_name='stages')
    op.drop_index(op.f('ix_stages_id'), table_name='stages')
    op.drop_index(op.f('ix_stage_instances_status_id'), table_name='stage_instances')
    op.drop_index(op.f('ix_stage_instances_stage_id'), table_name='stage_instances')
    op.drop_index(op.f('ix_stage_instances_pipeline_instance_id'), table_name='stage_instances')
    op.drop_index(op.f('ix_stage_instances_id'), table_name='stage_instances')
    op.drop_index(op.f('ix_qa_tests_id'), table_name='qa_tests')
    op.drop_index(op.f('ix_qa_test_histories_test_id'), table_name='qa_test_histories')
    op.drop_index(op.f('ix_qa_test_histories_status_id'), table_name='qa_test_histories')
    op.drop_index(op.f('ix_qa_test_histories_pipeline_instance_id'), table_name='qa_test_histories')
    op.drop_index(op.f('ix_qa_test_histories_id'), table_name='qa_test_histories')
    op.drop_index(op.f('ix_qa_test_histories_action_instance_id'), table_name='qa_test_histories')
    op.drop_index(op.f('ix_pipelines_id'), table_name='pipelines')
    op.drop_index(op.f('ix_pipeline_statistics_statistics_id'), table_name='pipeline_statistics')
    op.drop_index(op.f('ix_pipeline_statistics_pipeline_instance_id'), table_name='pipeline_statistics')
    op.drop_index(op.f('ix_pipeline_statistics_id'), table_name='pipeline_statistics')
    op.drop_index(op.f('ix_pipeline_parameters_pipeline_instance_id'), table_name='pipeline_parameters')
    op.drop_index(op.f('ix_pipeline_parameters_parameter'), table_name='pipeline_parameters')
    op.drop_index(op.f('ix_pipeline_parameters_id'), table_name='pipeline_parameters')
    op.drop_index(op.f('ix_pipeline_instances_status_id'), table_name='pipeline_instances')
    op.drop_index(op.f('ix_pipeline_instances_pipeline_id'), table_name='pipeline_instances')
    op.drop_index(op.f('ix_pipeline_instances_id'), table_name='pipeline_instances')
    op.drop_index(op.f('ix_actions_workflow_id'), table_name='actions')
    op.drop_index(op.f('ix_actions_pipeline_id'), table_name='actions')
    op.drop_index(op.f('ix_actions_id'), table_name='actions')
    if 'sqlite' != op.get_context().dialect.name:
        op.alter_column('actions', 'name',
                   existing_type=sa.VARCHAR(length=100),
                   nullable=True)
    op.drop_index(op.f('ix_action_instances_workflow_instance_id'), table_name='action_instances')
    op.drop_index(op.f('ix_action_instances_status_id'), table_name='action_instances')
    op.drop_index(op.f('ix_action_instances_pipeline_instance_id'), table_name='action_instances')
    op.drop_index(op.f('ix_action_instances_id'), table_name='action_instances')
    op.drop_index(op.f('ix_action_instances_action_id'), table_name='action_instances')
    ### end Alembic commands ###
