"""Rename certified tables to published

Revision ID: 132e31899fd0
Revises: 3ff22fa8cb2e
Create Date: 2022-05-31 10:37:47.213625

"""

# revision identifiers, used by Alembic.
revision = '132e31899fd0'
down_revision = '3ff22fa8cb2e'
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
    op.execute("ALTER TABLE certified_appropriation RENAME TO published_appropriation")
    op.execute("ALTER TABLE published_appropriation RENAME COLUMN certified_appropriation_id TO published_appropriation_id")
    op.execute("ALTER SEQUENCE certified_appropriation_certified_appropriation_id_seq RENAME TO published_appropriation_published_appropriation_id_seq")
    op.execute("ALTER TABLE published_appropriation RENAME CONSTRAINT fk_certified_appropriation_submission_id TO fk_published_appropriation_submission_id")
    op.execute("ALTER INDEX certified_appropriation_pkey RENAME TO published_appropriation_pkey")
    op.execute("ALTER INDEX ix_certified_appropriation_submission_id RENAME TO ix_published_appropriation_submission_id")

    # Object Class Program Activity
    op.execute("ALTER TABLE certified_object_class_program_activity RENAME TO published_object_class_program_activity")
    op.execute("ALTER TABLE published_object_class_program_activity RENAME COLUMN certified_object_class_program_activity_id TO published_object_class_program_activity_id")
    op.execute("ALTER SEQUENCE certified_object_class_progra_certified_object_class_progra_seq RENAME TO published_object_class_progra_published_object_class_progra_seq")
    op.execute("ALTER TABLE published_object_class_program_activity RENAME CONSTRAINT fk_certified_object_class_program_activity_submission_id TO fk_published_object_class_program_activity_submission_id")
    op.execute("ALTER INDEX certified_object_class_program_activity_pkey RENAME TO published_object_class_program_activity_pkey")
    op.execute("ALTER INDEX ix_certified_object_class_program_activity_submission_id RENAME TO ix_published_object_class_program_activity_submission_id")

    # Award Financial
    op.execute("ALTER TABLE certified_award_financial RENAME TO published_award_financial")
    op.execute("ALTER TABLE published_award_financial RENAME COLUMN certified_award_financial_id TO published_award_financial_id")
    op.execute("ALTER SEQUENCE certified_award_financial_certified_award_financial_id_seq RENAME TO published_award_financial_published_award_financial_id_seq")
    op.execute("ALTER TABLE published_award_financial RENAME CONSTRAINT fk_certified_award_financial_submission_id TO fk_published_award_financial_submission_id")
    op.execute("ALTER INDEX certified_award_financial_pkey RENAME TO published_award_financial_pkey")
    op.execute("ALTER INDEX ix_certified_award_financial_submission_id RENAME TO ix_published_award_financial_submission_id")

    # Award Procurement
    op.execute("ALTER TABLE certified_award_procurement RENAME TO published_award_procurement")
    op.execute("ALTER TABLE published_award_procurement RENAME COLUMN certified_award_procurement_id TO published_award_procurement_id")
    op.execute("ALTER SEQUENCE certified_award_procurement_certified_award_procurement_id_seq RENAME TO published_award_procurement_published_award_procurement_id_seq")
    op.execute("ALTER TABLE published_award_procurement RENAME CONSTRAINT fk_award_procurement_submission_id TO fk_published_award_procurement_submission_id")
    op.execute("ALTER INDEX certified_award_procurement_pkey RENAME TO published_award_procurement_pkey")
    op.execute("ALTER INDEX ix_certified_award_procurement_submission_id RENAME TO ix_published_award_procurement_submission_id")

    # Award Financial Assistance
    op.execute("ALTER TABLE certified_award_financial_assistance RENAME TO published_award_financial_assistance")
    op.execute("ALTER TABLE published_award_financial_assistance RENAME COLUMN certified_award_financial_assistance_id TO published_award_financial_assistance_id")
    op.execute("ALTER SEQUENCE certified_award_financial_ass_certified_award_financial_ass_seq RENAME TO published_award_financial_ass_published_award_financial_ass_seq")
    op.execute("ALTER TABLE published_award_financial_assistance RENAME CONSTRAINT fk_award_financial_assistance_submission_id TO fk_published_award_financial_assistance_submission_id")
    op.execute("ALTER INDEX certified_award_financial_assistance_pkey RENAME TO published_award_financial_assistance_pkey")
    op.execute("ALTER INDEX ix_certified_award_financial_assistance_submission_id RENAME TO ix_published_award_financial_assistance_submission_id")

    # Flex Field
    op.execute("ALTER TABLE certified_flex_field RENAME TO published_flex_field")
    op.execute("ALTER TABLE published_flex_field RENAME COLUMN certified_flex_field_id TO published_flex_field_id")
    op.execute("ALTER SEQUENCE certified_flex_field_certified_flex_field_id_seq RENAME TO published_flex_field_published_flex_field_id_seq")
    op.execute("ALTER TABLE published_flex_field RENAME CONSTRAINT fk_certified_flex_field_submission_id TO fk_published_flex_field_submission_id")
    op.execute("ALTER INDEX certified_flex_field_pkey RENAME TO published_flex_field_pkey")
    op.execute("ALTER INDEX ix_certified_flex_field_submission_id RENAME TO ix_published_flex_field_submission_id")

    # Total Obligations
    op.execute("ALTER TABLE certified_total_obligations RENAME TO published_total_obligations")
    op.execute("ALTER TABLE published_total_obligations RENAME COLUMN certified_total_obligations_id TO published_total_obligations_id")
    op.execute("ALTER SEQUENCE certified_total_obligations_certified_total_obligations_id_seq RENAME TO published_total_obligations_published_total_obligations_id_seq")
    op.execute("ALTER TABLE published_total_obligations RENAME CONSTRAINT fk_certified_total_obligations_submission_id TO fk_published_total_obligations_submission_id")
    op.execute("ALTER INDEX certified_total_obligations_pkey RENAME TO published_total_obligations_pkey")
    op.execute("ALTER INDEX ix_certified_total_obligations_submission_id RENAME TO ix_published_total_obligations_submission_id")

    # Comment
    op.execute("ALTER TABLE certified_comment RENAME TO published_comment")
    op.execute("ALTER TABLE published_comment RENAME COLUMN certified_comment_id TO published_comment_id")
    op.execute("ALTER SEQUENCE certified_comment_certified_comment_id_seq RENAME TO published_comment_published_comment_id_seq")
    op.execute("ALTER TABLE published_comment RENAME CONSTRAINT fk_submission TO fk_published_comment_submission_id")
    op.execute("ALTER TABLE published_comment RENAME CONSTRAINT fk_file_type TO fk_published_comment_file_type_id")
    op.execute("ALTER INDEX certified_comment_pkey RENAME TO published_comment_pkey")
    op.execute("ALTER INDEX uniq_cert_comment_submission_file_type RENAME TO uniq_pub_comment_submission_file_type")

    # Error Metadata
    op.execute("ALTER TABLE certified_error_metadata RENAME TO published_error_metadata")
    op.execute("ALTER TABLE published_error_metadata RENAME COLUMN certified_error_metadata_id TO published_error_metadata_id")
    op.execute("ALTER SEQUENCE certified_error_metadata_certified_error_metadata_id_seq RENAME TO published_error_metadata_published_error_metadata_id_seq")
    op.execute("ALTER TABLE published_error_metadata RENAME CONSTRAINT fk_error_metadata_job TO fk_published_error_metadata_job_id")
    op.execute("ALTER TABLE published_error_metadata RENAME CONSTRAINT certified_error_metadata_error_type_id_fkey TO published_error_metadata_error_type_id_fkey")
    op.execute("ALTER TABLE published_error_metadata RENAME CONSTRAINT fk_file_type_file_status_id TO fk_published_error_metadata_file_type_id")
    op.execute("ALTER TABLE published_error_metadata RENAME CONSTRAINT fk_target_file_type_file_status_id TO fk_published_error_metadata_target_file_type_id")
    op.execute("ALTER TABLE published_error_metadata RENAME CONSTRAINT fk_error_severity_id TO fk_published_error_metadata_severity_id")
    op.execute("ALTER INDEX certified_error_metadata_pkey RENAME TO published_error_metadata_pkey")
    # ### end Alembic commands ###


def downgrade_data_broker():
    # ### commands auto generated by Alembic - please adjust! ###
    op.execute("ALTER INDEX ix_published_appropriation_submission_id RENAME TO ix_certified_appropriation_submission_id")
    op.execute("ALTER INDEX published_appropriation_pkey RENAME TO certified_appropriation_pkey")
    op.execute("ALTER TABLE published_appropriation RENAME CONSTRAINT fk_published_appropriation_submission_id TO fk_certified_appropriation_submission_id")
    op.execute("ALTER SEQUENCE published_appropriation_published_appropriation_id_seq RENAME TO certified_appropriation_certified_appropriation_id_seq")
    op.execute("ALTER TABLE published_appropriation RENAME COLUMN published_appropriation_id TO certified_appropriation_id")
    op.execute("ALTER TABLE published_appropriation RENAME TO certified_appropriation")

    # Object Class Program Activity
    op.execute("ALTER INDEX ix_published_object_class_program_activity_submission_id RENAME TO ix_certified_object_class_program_activity_submission_id")
    op.execute("ALTER INDEX published_object_class_program_activity_pkey RENAME TO certified_object_class_program_activity_pkey")
    op.execute("ALTER TABLE published_object_class_program_activity RENAME CONSTRAINT fk_published_object_class_program_activity_submission_id TO fk_certified_object_class_program_activity_submission_id")
    op.execute("ALTER SEQUENCE published_object_class_progra_published_object_class_progra_seq RENAME TO certified_object_class_progra_certified_object_class_progra_seq")
    op.execute("ALTER TABLE published_object_class_program_activity RENAME COLUMN published_object_class_program_activity_id TO certified_object_class_program_activity_id")
    op.execute("ALTER TABLE published_object_class_program_activity RENAME TO certified_object_class_program_activity")

    # Award Financial
    op.execute("ALTER INDEX ix_published_award_financial_submission_id RENAME TO ix_certified_award_financial_submission_id")
    op.execute("ALTER INDEX published_award_financial_pkey RENAME TO certified_award_financial_pkey")
    op.execute("ALTER TABLE published_award_financial RENAME CONSTRAINT fk_published_award_financial_submission_id TO fk_certified_award_financial_submission_id")
    op.execute("ALTER SEQUENCE published_award_financial_published_award_financial_id_seq RENAME TO certified_award_financial_certified_award_financial_id_seq")
    op.execute("ALTER TABLE published_award_financial RENAME COLUMN published_award_financial_id TO certified_award_financial_id")
    op.execute("ALTER TABLE published_award_financial RENAME TO certified_award_financial")

    # Award Procurement
    op.execute("ALTER INDEX ix_published_award_procurement_submission_id RENAME TO ix_certified_award_procurement_submission_id")
    op.execute("ALTER INDEX published_award_procurement_pkey RENAME TO certified_award_procurement_pkey")
    op.execute("ALTER TABLE published_award_procurement RENAME CONSTRAINT fk_published_award_procurement_submission_id TO fk_award_procurement_submission_id")
    op.execute("ALTER SEQUENCE published_award_procurement_published_award_procurement_id_seq RENAME TO certified_award_procurement_certified_award_procurement_id_seq")
    op.execute("ALTER TABLE published_award_procurement RENAME COLUMN published_award_procurement_id TO certified_award_procurement_id")
    op.execute("ALTER TABLE published_award_procurement RENAME TO certified_award_procurement")

    # Award Financial Assistance
    op.execute("ALTER INDEX ix_published_award_financial_assistance_submission_id RENAME TO ix_certified_award_financial_assistance_submission_id")
    op.execute("ALTER INDEX published_award_financial_assistance_pkey RENAME TO certified_award_financial_assistance_pkey")
    op.execute("ALTER TABLE published_award_financial_assistance RENAME CONSTRAINT fk_published_award_financial_assistance_submission_id TO fk_award_financial_assistance_submission_id")
    op.execute("ALTER SEQUENCE published_award_financial_ass_published_award_financial_ass_seq RENAME TO certified_award_financial_ass_certified_award_financial_ass_seq")
    op.execute("ALTER TABLE published_award_financial_assistance RENAME COLUMN published_award_financial_assistance_id TO certified_award_financial_assistance_id")
    op.execute("ALTER TABLE published_award_financial_assistance RENAME TO certified_award_financial_assistance")

    # Flex Field
    op.execute("ALTER INDEX ix_published_flex_field_submission_id RENAME TO ix_certified_flex_field_submission_id")
    op.execute("ALTER INDEX published_flex_field_pkey RENAME TO certified_flex_field_pkey")
    op.execute("ALTER TABLE published_flex_field RENAME CONSTRAINT fk_published_flex_field_submission_id TO fk_certified_flex_field_submission_id")
    op.execute("ALTER SEQUENCE published_flex_field_published_flex_field_id_seq RENAME TO certified_flex_field_certified_flex_field_id_seq")
    op.execute("ALTER TABLE published_flex_field RENAME COLUMN published_flex_field_id TO certified_flex_field_id")
    op.execute("ALTER TABLE published_flex_field RENAME TO certified_flex_field")

    # Total Obligations
    op.execute("ALTER INDEX ix_published_total_obligations_submission_id RENAME TO ix_certified_total_obligations_submission_id")
    op.execute("ALTER INDEX published_total_obligations_pkey RENAME TO certified_total_obligations_pkey")
    op.execute("ALTER TABLE published_total_obligations RENAME CONSTRAINT fk_published_total_obligations_submission_id TO fk_certified_total_obligations_submission_id")
    op.execute("ALTER SEQUENCE published_total_obligations_published_total_obligations_id_seq RENAME TO certified_total_obligations_certified_total_obligations_id_seq")
    op.execute("ALTER TABLE published_total_obligations RENAME COLUMN published_total_obligations_id TO certified_total_obligations_id")
    op.execute("ALTER TABLE published_total_obligations RENAME TO certified_total_obligations")

    # Comment
    op.execute("ALTER INDEX uniq_pub_comment_submission_file_type RENAME TO uniq_cert_comment_submission_file_type")
    op.execute("ALTER INDEX published_comment_pkey RENAME TO certified_comment_pkey")
    op.execute("ALTER TABLE published_comment RENAME CONSTRAINT fk_published_comment_file_type_id TO fk_file_type")
    op.execute("ALTER TABLE published_comment RENAME CONSTRAINT fk_published_comment_submission_id TO fk_submission")
    op.execute("ALTER SEQUENCE published_comment_published_comment_id_seq RENAME TO certified_comment_certified_comment_id_seq")
    op.execute("ALTER TABLE published_comment RENAME COLUMN published_comment_id TO certified_comment_id")
    op.execute("ALTER TABLE published_comment RENAME TO certified_comment")

    # Error Metadata
    op.execute("ALTER INDEX published_error_metadata_pkey RENAME TO certified_error_metadata_pkey")
    op.execute("ALTER TABLE published_error_metadata RENAME CONSTRAINT fk_published_error_metadata_severity_id TO fk_error_severity_id")
    op.execute("ALTER TABLE published_error_metadata RENAME CONSTRAINT fk_published_error_metadata_target_file_type_id TO fk_target_file_type_file_status_id")
    op.execute("ALTER TABLE published_error_metadata RENAME CONSTRAINT fk_published_error_metadata_file_type_id TO fk_file_type_file_status_id")
    op.execute("ALTER TABLE published_error_metadata RENAME CONSTRAINT published_error_metadata_error_type_id_fkey TO certified_error_metadata_error_type_id_fkey")
    op.execute("ALTER TABLE published_error_metadata RENAME CONSTRAINT fk_published_error_metadata_job_id TO fk_error_metadata_job")
    op.execute("ALTER SEQUENCE published_error_metadata_published_error_metadata_id_seq RENAME TO certified_error_metadata_certified_error_metadata_id_seq")
    op.execute("ALTER TABLE published_error_metadata RENAME COLUMN published_error_metadata_id TO certified_error_metadata_id")
    op.execute("ALTER TABLE published_error_metadata RENAME TO certified_error_metadata")
    # ### end Alembic commands ###

