"""qa test mapping

Revision ID: 593023a41b6d
Revises: e2a50a08334a
Create Date: 2016-05-19 16:09:12.356379

"""

# revision identifiers, used by Alembic.

revision = '593023a41b6d'
down_revision = '63ed28aeec3d'
branch_labels = None
depends_on = None

from alembic import op
import sqlalchemy as sa


def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.create_table('qa_areas',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('name', sa.String(length=250), nullable=False),
    sa.PrimaryKeyConstraint('id'),
    mysql_engine='InnoDB'
    )
    op.create_index(op.f('ix_qa_areas_id'), 'qa_areas', ['id'], unique=False)
    op.create_index(op.f('ix_qa_areas_name'), 'qa_areas', ['name'], unique=False)
    op.create_table('qa_behavior_points',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('name', sa.String(length=400), nullable=False),
    sa.PrimaryKeyConstraint('id'),
    mysql_engine='InnoDB'
    )
    op.create_index(op.f('ix_qa_behavior_points_id'), 'qa_behavior_points', ['id'], unique=False)
    op.create_index(op.f('ix_qa_behavior_points_name'), 'qa_behavior_points', ['name'], unique=False)
    op.create_table('qa_features',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('name', sa.String(length=250), nullable=False),
    sa.PrimaryKeyConstraint('id'),
    mysql_engine='InnoDB'
    )
    op.create_index(op.f('ix_qa_features_id'), 'qa_features', ['id'], unique=False)
    op.create_index(op.f('ix_qa_features_name'), 'qa_features', ['name'], unique=False)
    op.create_table('tags',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('name', sa.String(length=100), nullable=False),
    sa.PrimaryKeyConstraint('id'),
    mysql_engine='InnoDB'
    )
    op.create_index(op.f('ix_tags_id'), 'tags', ['id'], unique=False)
    op.create_index(op.f('ix_tags_name'), 'tags', ['name'], unique=False)
    op.create_table('qa_test_mappings',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('area_id', sa.Integer(), nullable=False),
    sa.Column('feature_id', sa.Integer(), nullable=False),
    sa.Column('behavior_id', sa.Integer(), nullable=False),
    sa.Column('test_id', sa.Integer(), nullable=False),
    sa.ForeignKeyConstraint(['area_id'], ['qa_areas.id'], ),
    sa.ForeignKeyConstraint(['behavior_id'], ['qa_behavior_points.id'], ),
    sa.ForeignKeyConstraint(['feature_id'], ['qa_features.id'], ),
    sa.ForeignKeyConstraint(['test_id'], ['qa_tests.id'], ),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('area_id', 'feature_id', 'behavior_id', 'test_id', name='uix_qatm')
    )
    op.create_index(op.f('ix_qa_test_mappings_id'), 'qa_test_mappings', ['id'], unique=False)
    op.create_table('qa_test_map_tags',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('qa_testmap_id', sa.Integer(), nullable=False),
    sa.Column('tag_id', sa.Integer(), nullable=False),
    sa.ForeignKeyConstraint(['qa_testmap_id'], ['qa_test_mappings.id'], ),
    sa.ForeignKeyConstraint(['tag_id'], ['tags.id'], ),
    sa.PrimaryKeyConstraint('id'),
    mysql_engine='InnoDB'
    )
    op.create_index(op.f('ix_qa_test_map_tags_id'), 'qa_test_map_tags', ['id'], unique=False)
    op.create_index(op.f('ix_qa_test_map_tags_qa_testmap_id'), 'qa_test_map_tags', ['qa_testmap_id'], unique=False)
    op.create_index(op.f('ix_qa_test_map_tags_tag_id'), 'qa_test_map_tags', ['tag_id'], unique=False)
    ### end Alembic commands ###


def downgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.drop_table('qa_test_map_tags')
    op.drop_index(op.f('ix_qa_test_mappings_id'), table_name='qa_test_mappings')
    op.drop_table('qa_test_mappings')
    op.drop_index(op.f('ix_tags_name'), table_name='tags')
    op.drop_index(op.f('ix_tags_id'), table_name='tags')
    op.drop_table('tags')
    op.drop_index(op.f('ix_qa_features_name'), table_name='qa_features')
    op.drop_index(op.f('ix_qa_features_id'), table_name='qa_features')
    op.drop_table('qa_features')
    op.drop_index(op.f('ix_qa_behavior_points_name'), table_name='qa_behavior_points')
    op.drop_index(op.f('ix_qa_behavior_points_id'), table_name='qa_behavior_points')
    op.drop_table('qa_behavior_points')
    op.drop_index(op.f('ix_qa_areas_name'), table_name='qa_areas')
    op.drop_index(op.f('ix_qa_areas_id'), table_name='qa_areas')
    op.drop_table('qa_areas')

    ### end Alembic commands ###
