"""Create certified_error_metadata table

Revision ID: 87d7a9b0ea7b
Revises: 51b1bbc0bfde
Create Date: 2019-08-01 15:29:11.406208

"""

# revision identifiers, used by Alembic.
revision = '87d7a9b0ea7b'
down_revision = '51b1bbc0bfde'
branch_labels = None
depends_on = None

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

def upgrade(engine_name):
    globals()["upgrade_%s" % engine_name]()


def downgrade(engine_name):
    globals()["downgrade_%s" % engine_name]()





def upgrade_data_broker():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('certified_error_metadata',
    sa.Column('created_at', sa.DateTime(), nullable=True),
    sa.Column('updated_at', sa.DateTime(), nullable=True),
    sa.Column('certified_error_metadata_id', sa.Integer(), nullable=False),
    sa.Column('job_id', sa.Integer(), nullable=True),
    sa.Column('filename', sa.Text(), nullable=True),
    sa.Column('field_name', sa.Text(), nullable=True),
    sa.Column('error_type_id', sa.Integer(), nullable=True),
    sa.Column('occurrences', sa.Integer(), nullable=True),
    sa.Column('first_row', sa.Integer(), nullable=True),
    sa.Column('rule_failed', sa.Text(), nullable=True),
    sa.Column('file_type_id', sa.Integer(), nullable=True),
    sa.Column('target_file_type_id', sa.Integer(), nullable=True),
    sa.Column('original_rule_label', sa.Text(), nullable=True),
    sa.Column('severity_id', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['error_type_id'], ['error_type.error_type_id'], ),
    sa.ForeignKeyConstraint(['file_type_id'], ['file_type.file_type_id'], name='fk_file_type_file_status_id'),
    sa.ForeignKeyConstraint(['job_id'], ['job.job_id'], name='fk_error_metadata_job', ondelete='CASCADE'),
    sa.ForeignKeyConstraint(['severity_id'], ['rule_severity.rule_severity_id'], name='fk_error_severity_id'),
    sa.ForeignKeyConstraint(['target_file_type_id'], ['file_type.file_type_id'], name='fk_target_file_type_file_status_id'),
    sa.PrimaryKeyConstraint('certified_error_metadata_id')
    )
    # ### end Alembic commands ###


def downgrade_data_broker():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_table('certified_error_metadata')
    # ### end Alembic commands ###

