"""Add columns to detached_award_procurement and move data

Revision ID: 1fc4844837cf
Revises: 9960bbbe4d92
Create Date: 2017-09-12 11:19:41.697007

"""

# revision identifiers, used by Alembic.
revision = '1fc4844837cf'
down_revision = '9960bbbe4d92'
branch_labels = None
depends_on = None

from alembic import op
import sqlalchemy as sa
from datetime import datetime


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.add_column('detached_award_procurement', sa.Column('base_and_all_options_value', sa.Text(), nullable=True))
    op.add_column('detached_award_procurement', sa.Column('base_exercised_options_val', sa.Text(), nullable=True))
    op.add_column('detached_award_procurement', sa.Column('total_obligated_amount', sa.Text(), nullable=True))
    op.execute("""
        UPDATE detached_award_procurement
        SET base_and_all_options_value = potential_total_value_awar,
            base_exercised_options_val = current_total_value_award,
            potential_total_value_awar = NULL,
            current_total_value_award = NULL
    """)
    ### end Alembic commands ###


def downgrade_data_broker():
    ### commands auto generated by Alembic - please adjust! ###
    op.execute("""
            UPDATE detached_award_procurement
            SET potential_total_value_awar = base_and_all_options_value,
                current_total_value_award = base_exercised_options_val
        """)
    op.drop_column('detached_award_procurement', 'total_obligated_amount')
    op.drop_column('detached_award_procurement', 'base_exercised_options_val')
    op.drop_column('detached_award_procurement', 'base_and_all_options_value')
    ### end Alembic commands ###

