"""add detached D2 submission models

Revision ID: 4a1988f74a78
Revises: 4bf29ae16467
Create Date: 2017-01-20 11:40:50.782401

"""

# revision identifiers, used by Alembic.
revision = '4a1988f74a78'
down_revision = '4bf29ae16467'
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('detached_award_financial_assistance',
    sa.Column('created_at', sa.DateTime(), nullable=True),
    sa.Column('updated_at', sa.DateTime(), nullable=True),
    sa.Column('detached_award_financial_assistance_id', sa.Integer(), nullable=False),
    sa.Column('submission_id', sa.Integer(), nullable=False),
    sa.Column('job_id', sa.Integer(), nullable=False),
    sa.Column('row_number', sa.Integer(), nullable=False),
    sa.Column('action_date', sa.Text(), nullable=True),
    sa.Column('action_type', sa.Text(), nullable=True),
    sa.Column('assistance_type', sa.Text(), nullable=True),
    sa.Column('award_description', sa.Text(), nullable=True),
    sa.Column('awardee_or_recipient_legal', sa.Text(), nullable=True),
    sa.Column('awardee_or_recipient_uniqu', sa.Text(), nullable=True),
    sa.Column('awarding_agency_code', sa.Text(), nullable=True),
    sa.Column('awarding_agency_name', sa.Text(), nullable=True),
    sa.Column('awarding_office_code', sa.Text(), nullable=True),
    sa.Column('awarding_office_name', sa.Text(), nullable=True),
    sa.Column('awarding_sub_tier_agency_c', sa.Text(), nullable=True),
    sa.Column('awarding_sub_tier_agency_n', sa.Text(), nullable=True),
    sa.Column('award_modification_amendme', sa.Text(), nullable=True),
    sa.Column('business_funds_indicator', sa.Text(), nullable=True),
    sa.Column('business_types', sa.Text(), nullable=True),
    sa.Column('cfda_number', sa.Text(), nullable=True),
    sa.Column('cfda_title', sa.Text(), nullable=True),
    sa.Column('correction_late_delete_ind', sa.Text(), nullable=True),
    sa.Column('face_value_loan_guarantee', sa.Numeric(), nullable=True),
    sa.Column('fain', sa.Text(), nullable=True),
    sa.Column('federal_action_obligation', sa.Numeric(), nullable=True),
    sa.Column('fiscal_year_and_quarter_co', sa.Text(), nullable=True),
    sa.Column('funding_agency_code', sa.Text(), nullable=True),
    sa.Column('funding_agency_name', sa.Text(), nullable=True),
    sa.Column('funding_office_name', sa.Text(), nullable=True),
    sa.Column('funding_office_code', sa.Text(), nullable=True),
    sa.Column('funding_sub_tier_agency_co', sa.Text(), nullable=True),
    sa.Column('funding_sub_tier_agency_na', sa.Text(), nullable=True),
    sa.Column('legal_entity_address_line1', sa.Text(), nullable=True),
    sa.Column('legal_entity_address_line2', sa.Text(), nullable=True),
    sa.Column('legal_entity_address_line3', sa.Text(), nullable=True),
    sa.Column('legal_entity_city_code', sa.Text(), nullable=True),
    sa.Column('legal_entity_city_name', sa.Text(), nullable=True),
    sa.Column('legal_entity_congressional', sa.Text(), nullable=True),
    sa.Column('legal_entity_country_code', sa.Text(), nullable=True),
    sa.Column('legal_entity_county_code', sa.Text(), nullable=True),
    sa.Column('legal_entity_county_name', sa.Text(), nullable=True),
    sa.Column('legal_entity_foreign_city', sa.Text(), nullable=True),
    sa.Column('legal_entity_foreign_posta', sa.Text(), nullable=True),
    sa.Column('legal_entity_foreign_provi', sa.Text(), nullable=True),
    sa.Column('legal_entity_state_code', sa.Text(), nullable=True),
    sa.Column('legal_entity_state_name', sa.Text(), nullable=True),
    sa.Column('legal_entity_zip5', sa.Text(), nullable=True),
    sa.Column('legal_entity_zip_last4', sa.Text(), nullable=True),
    sa.Column('non_federal_funding_amount', sa.Numeric(), nullable=True),
    sa.Column('original_loan_subsidy_cost', sa.Numeric(), nullable=True),
    sa.Column('period_of_performance_curr', sa.Text(), nullable=True),
    sa.Column('period_of_performance_star', sa.Text(), nullable=True),
    sa.Column('place_of_performance_city', sa.Text(), nullable=True),
    sa.Column('place_of_performance_code', sa.Text(), nullable=True),
    sa.Column('place_of_performance_congr', sa.Text(), nullable=True),
    sa.Column('place_of_perform_country_c', sa.Text(), nullable=True),
    sa.Column('place_of_perform_county_na', sa.Text(), nullable=True),
    sa.Column('place_of_performance_forei', sa.Text(), nullable=True),
    sa.Column('place_of_perform_state_nam', sa.Text(), nullable=True),
    sa.Column('place_of_performance_zip4a', sa.Text(), nullable=True),
    sa.Column('record_type', sa.Integer(), nullable=True),
    sa.Column('sai_number', sa.Text(), nullable=True),
    sa.Column('total_funding_amount', sa.Numeric(), nullable=True),
    sa.Column('uri', sa.Text(), nullable=True),
    sa.Column('is_valid', sa.Boolean(), server_default='False', nullable=False),
    sa.PrimaryKeyConstraint('detached_award_financial_assistance_id')
    )
    op.create_index(op.f('ix_detached_award_financial_assistance_fain'), 'detached_award_financial_assistance', ['fain'], unique=False)
    op.create_index(op.f('ix_detached_award_financial_assistance_job_id'), 'detached_award_financial_assistance', ['job_id'], unique=False)
    op.create_index(op.f('ix_detached_award_financial_assistance_submission_id'), 'detached_award_financial_assistance', ['submission_id'], unique=False)
    op.create_index(op.f('ix_detached_award_financial_assistance_uri'), 'detached_award_financial_assistance', ['uri'], unique=False)
    op.create_table('submission_sub_tier_affiliation',
    sa.Column('created_at', sa.DateTime(), nullable=True),
    sa.Column('updated_at', sa.DateTime(), nullable=True),
    sa.Column('submission_sub_tier_affiliation_id', sa.Integer(), nullable=False),
    sa.Column('submission_id', sa.Integer(), nullable=True),
    sa.Column('sub_tier_agency_id', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['sub_tier_agency_id'], ['sub_tier_agency.sub_tier_agency_id'], name='fk_sub_tier_submission_affiliation_agency_id'),
    sa.ForeignKeyConstraint(['submission_id'], ['submission.submission_id'], name='fk_submission_sub_tier_affiliation_id'),
    sa.PrimaryKeyConstraint('submission_sub_tier_affiliation_id')
    )
    op.add_column('submission', sa.Column('d2_submission', sa.Boolean(), server_default='False', nullable=False))
    ### end Alembic commands ###


def downgrade_data_broker():
    ### commands auto generated by Alembic - please adjust! ###
    op.drop_column('submission', 'd2_submission')
    op.drop_table('submission_sub_tier_affiliation')
    op.drop_index(op.f('ix_detached_award_financial_assistance_uri'), table_name='detached_award_financial_assistance')
    op.drop_index(op.f('ix_detached_award_financial_assistance_submission_id'), table_name='detached_award_financial_assistance')
    op.drop_index(op.f('ix_detached_award_financial_assistance_job_id'), table_name='detached_award_financial_assistance')
    op.drop_index(op.f('ix_detached_award_financial_assistance_fain'), table_name='detached_award_financial_assistance')
    op.drop_table('detached_award_financial_assistance')
    ### end Alembic commands ###

