"""Add FailureReason

Revision ID: 1c5907e309f1
Revises: 4a12e7f0159d
Create Date: 2014-06-02 15:31:02.991394

"""

# revision identifiers, used by Alembic.
revision = '1c5907e309f1'
down_revision = '4a12e7f0159d'

from alembic import op
import sqlalchemy as sa


def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        'failurereason',
        sa.Column('id', sa.GUID(), nullable=False),
        sa.Column('step_id', sa.GUID(), nullable=False),
        sa.Column('job_id', sa.GUID(), nullable=False),
        sa.Column('build_id', sa.GUID(), nullable=False),
        sa.Column('project_id', sa.GUID(), nullable=False),
        sa.Column('reason', sa.String(length=32), nullable=False),
        sa.Column('date_created', sa.DateTime(), nullable=False),
        sa.ForeignKeyConstraint(['build_id'], ['build.id'], ondelete='CASCADE'),
        sa.ForeignKeyConstraint(['job_id'], ['job.id'], ondelete='CASCADE'),
        sa.ForeignKeyConstraint(['project_id'], ['project.id'], ondelete='CASCADE'),
        sa.ForeignKeyConstraint(['step_id'], ['jobstep.id'], ondelete='CASCADE'),
        sa.PrimaryKeyConstraint('id'),
        sa.UniqueConstraint('step_id', 'reason', name='unq_failurereason_key')
    )
    op.create_index('idx_failurereason_build_id', 'failurereason', ['build_id'], unique=False)
    op.create_index('idx_failurereason_job_id', 'failurereason', ['job_id'], unique=False)
    op.create_index('idx_failurereason_project_id', 'failurereason', ['project_id'], unique=False)


def downgrade():
    op.drop_table('failurereason')
