"""creating revalidation threshold and adding last validated

Revision ID: 21d297a08e18
Revises: 322a73dd080d
Create Date: 2017-03-02 22:46:31.824508

"""

# revision identifiers, used by Alembic.
revision = '21d297a08e18'
down_revision = '322a73dd080d'
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('revalidation_threshold',
    sa.Column('created_at', sa.DateTime(), nullable=True),
    sa.Column('updated_at', sa.DateTime(), nullable=True),
    sa.Column('revalidation_date', sa.Date(), nullable=False),
    sa.PrimaryKeyConstraint('revalidation_date')
    )

    op.execute("INSERT INTO revalidation_threshold (revalidation_date) VALUES ('02/22/2017')")

    op.add_column('job', sa.Column('last_validated', sa.DateTime(), nullable=True))
    op.drop_column('submission', 'datetime_utc')

    ### end Alembic commands ###


def downgrade_data_broker():
    ### commands auto generated by Alembic - please adjust! ###
    op.add_column('submission', sa.Column('datetime_utc', postgresql.TIMESTAMP(), autoincrement=False, nullable=True))
    op.drop_column('job', 'last_validated')
    op.drop_table('revalidation_threshold')
    ### end Alembic commands ###

