"""Add certified_files_history table and update certify_history table

Revision ID: 52b3c1a122ce
Revises: 204e2cf584cd
Create Date: 2017-06-05 12:37:10.724212

"""

# revision identifiers, used by Alembic.
revision = '52b3c1a122ce'
down_revision = '204e2cf584cd'
branch_labels = None
depends_on = None

from alembic import op
import sqlalchemy as sa


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_files_history',
        sa.Column('created_at', sa.DateTime(), nullable=True),
        sa.Column('updated_at', sa.DateTime(), nullable=True),
        sa.Column('certified_files_history_id', sa.Integer(), nullable=False),
        sa.Column('certify_history_id', sa.Integer(), nullable=True),
        sa.Column('submission_id', sa.Integer(), nullable=True),
        sa.Column('filename', sa.Text(), nullable=True),
        sa.Column('file_type_id', sa.Integer(), nullable=True),
        sa.Column('warning_filename', sa.Text(), nullable=True),
        sa.Column('narrative', sa.Text(), nullable=True),
        sa.ForeignKeyConstraint(['certify_history_id'], ['certify_history.certify_history_id'], name='fk_certify_history_certified_files_id'),
        sa.ForeignKeyConstraint(['file_type_id'], ['file_type.file_type_id'], name='fk_certified_files_history_file_type'),
        sa.ForeignKeyConstraint(['submission_id'], ['submission.submission_id'], name='fk_certified_files_history_submission_id'),
        sa.PrimaryKeyConstraint('certified_files_history_id')
    )
    op.drop_constraint('fk_certify_history_submission_id', 'certify_history', type_='foreignkey')
    op.create_foreign_key('fk_certify_history_submission_id', 'certify_history', 'submission', ['submission_id'], ['submission_id'])
    ### end Alembic commands ###


def downgrade_data_broker():
    ### commands auto generated by Alembic - please adjust! ###
    op.drop_constraint('fk_certify_history_submission_id', 'certify_history', type_='foreignkey')
    op.create_foreign_key('fk_certify_history_submission_id', 'certify_history', 'submission', ['submission_id'], ['submission_id'], ondelete='CASCADE')
    op.drop_table('certified_files_history')
    ### end Alembic commands ###

