"""Add certifying user to submission and certification history table

Revision ID: d7e2e541f6d6
Revises: 21d297a08e18
Create Date: 2017-03-27 10:29:36.234172

"""

# revision identifiers, used by Alembic.
revision = 'd7e2e541f6d6'
down_revision = '21d297a08e18'
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('certify_history',
        sa.Column('created_at', sa.DateTime(), nullable=True),
        sa.Column('updated_at', sa.DateTime(), nullable=True),
        sa.Column('certify_history_id', sa.Integer(), nullable=False),
        sa.Column('submission_id', sa.Integer(), nullable=True),
        sa.Column('user_id', sa.Integer(), nullable=True),
        sa.ForeignKeyConstraint(['submission_id'], ['submission.submission_id'], name='fk_certify_history_submission_id', ondelete='CASCADE'),
        sa.ForeignKeyConstraint(['user_id'], ['users.user_id'], name='fk_certify_history_user', ondelete='SET NULL'),
        sa.PrimaryKeyConstraint('certify_history_id')
    )
    op.add_column('submission', sa.Column('certifying_user_id', sa.Integer(), nullable=True))
    op.create_foreign_key('fk_submission_certifying_user', 'submission', 'users', ['certifying_user_id'], ['user_id'], ondelete='SET NULL')
    ### end Alembic commands ###


def downgrade_data_broker():
    ### commands auto generated by Alembic - please adjust! ###
    op.drop_constraint('fk_submission_certifying_user', 'submission', type_='foreignkey')
    op.drop_column('submission', 'certifying_user_id')
    op.drop_table('certify_history')
    ### end Alembic commands ###

