"""Rename tas_id to account_num in staging tables

Revision ID: 91df6b691864
Revises: bbc020fa7961
Create Date: 2021-05-27 09:57:41.745637

"""

# revision identifiers, used by Alembic.
revision = '91df6b691864'
down_revision = 'bbc020fa7961'
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! ###
    # appropriation changes
    op.execute("ALTER TABLE appropriation RENAME COLUMN tas_id TO account_num")
    op.execute("ALTER INDEX ix_appropriation_tas_id RENAME TO ix_appropriation_account_num")
    op.execute("ALTER INDEX ix_appropriation_tas_id_submission_id RENAME TO ix_appropriation_account_num_submission_id")

    # object_class_program_activity changes
    op.execute("ALTER TABLE object_class_program_activity RENAME COLUMN tas_id TO account_num")
    op.execute("ALTER INDEX ix_oc_pa_tas_id_submission_id RENAME TO ix_oc_pa_account_num_submission_id")

    # award_financial changes
    op.execute("ALTER TABLE award_financial RENAME COLUMN tas_id TO account_num")
    op.execute("ALTER INDEX ix_award_financial_tas_id RENAME TO ix_award_financial_account_num")

    # certified table changes
    op.execute("ALTER TABLE certified_appropriation RENAME COLUMN tas_id TO account_num")
    op.execute("ALTER TABLE certified_object_class_program_activity RENAME COLUMN tas_id TO account_num")
    op.execute("ALTER TABLE certified_award_financial RENAME COLUMN tas_id TO account_num")
    # ### end Alembic commands ###


def downgrade_data_broker():
    # ### commands auto generated by Alembic - please adjust! ###
    # appropriation changes
    op.execute("ALTER TABLE appropriation RENAME COLUMN account_num TO tas_id")
    op.execute("ALTER INDEX ix_appropriation_account_num RENAME TO ix_appropriation_tas_id")
    op.execute("ALTER INDEX ix_appropriation_account_num_submission_id RENAME TO ix_appropriation_tas_id_submission_id")

    # object_class_program_activity changes
    op.execute("ALTER TABLE object_class_program_activity RENAME COLUMN account_num TO tas_id")
    op.execute("ALTER INDEX ix_oc_pa_account_num_submission_id RENAME TO ix_oc_pa_tas_id_submission_id")

    # award_financial changes
    op.execute("ALTER TABLE award_financial RENAME COLUMN account_num TO tas_id")
    op.execute("ALTER INDEX ix_award_financial_account_num RENAME TO ix_award_financial_tas_id")

    # certified table changes
    op.execute("ALTER TABLE certified_appropriation RENAME COLUMN account_num TO tas_id")
    op.execute("ALTER TABLE certified_object_class_program_activity RENAME COLUMN account_num TO tas_id")
    op.execute("ALTER TABLE certified_award_financial RENAME COLUMN account_num TO tas_id")
    # ### end Alembic commands ###

