"""replace FileRequest with FileGeneration

Revision ID: 8692ab1298e1
Revises: 4bbc47f2b48d
Create Date: 2018-10-24 14:54:39.278159

"""

# revision identifiers, used by Alembic.
revision = '8692ab1298e1'
down_revision = '4bbc47f2b48d'
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('file_generation',
    sa.Column('created_at', sa.DateTime(), nullable=True),
    sa.Column('updated_at', sa.DateTime(), nullable=True),
    sa.Column('file_generation_id', sa.Integer(), nullable=False),
    sa.Column('request_date', sa.Date(), nullable=False),
    sa.Column('start_date', sa.Date(), nullable=False),
    sa.Column('end_date', sa.Date(), nullable=False),
    sa.Column('agency_code', sa.Text(), nullable=False),
    sa.Column('agency_type', sa.Enum('awarding', 'funding', name='generation_agency_types'), server_default='awarding', nullable=False),
    sa.Column('file_type', sa.Enum('D1', 'D2', name='generation_file_types'), server_default='D1', nullable=False),
    sa.Column('file_path', sa.Text(), nullable=True),
    sa.Column('is_cached_file', sa.Boolean(), nullable=False),
    sa.PrimaryKeyConstraint('file_generation_id')
    )
    op.create_index(op.f('ix_file_generation_agency_code'), 'file_generation', ['agency_code'], unique=False)
    op.create_index(op.f('ix_file_generation_agency_type'), 'file_generation', ['agency_type'], unique=False)
    op.create_index(op.f('ix_file_generation_end_date'), 'file_generation', ['end_date'], unique=False)
    op.create_index(op.f('ix_file_generation_file_type'), 'file_generation', ['file_type'], unique=False)
    op.create_index(op.f('ix_file_generation_request_date'), 'file_generation', ['request_date'], unique=False)
    op.create_index(op.f('ix_file_generation_start_date'), 'file_generation', ['start_date'], unique=False)
    op.add_column('job', sa.Column('file_generation_id', sa.Integer(), nullable=True))
    op.create_foreign_key('fk_file_request_file_generation_id', 'job', 'file_generation', ['file_generation_id'], ['file_generation_id'], ondelete='SET NULL')
    op.drop_column('job', 'from_cached')
    # ### end Alembic commands ###


def downgrade_data_broker():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('job', sa.Column('from_cached', sa.BOOLEAN(), server_default=sa.text('false'), autoincrement=False, nullable=False))
    op.drop_constraint('fk_file_request_file_generation_id', 'job', type_='foreignkey')
    op.drop_column('job', 'file_generation_id')
    op.drop_index(op.f('ix_file_generation_start_date'), table_name='file_generation')
    op.drop_index(op.f('ix_file_generation_request_date'), table_name='file_generation')
    op.drop_index(op.f('ix_file_generation_file_type'), table_name='file_generation')
    op.drop_index(op.f('ix_file_generation_end_date'), table_name='file_generation')
    op.drop_index(op.f('ix_file_generation_agency_type'), table_name='file_generation')
    op.drop_index(op.f('ix_file_generation_agency_code'), table_name='file_generation')
    op.drop_table('file_generation')
    op.execute("""
        DROP TYPE generation_agency_types
    """)
    op.execute("""
        DROP TYPE generation_file_types
    """)
    # ### end Alembic commands ###


[((53, 4, 53, 158), 'alembic.op.create_foreign_key', 'op.create_foreign_key', (), '', False, 'from alembic import op\n'), ((54, 4, 54, 40), 'alembic.op.drop_column', 'op.drop_column', ({(54, 19, 54, 24): '"""job"""', (54, 26, 54, 39): '"""from_cached"""'}, {}), "('job', 'from_cached')", False, 'from alembic import op\n'), ((61, 4, 61, 87), 'alembic.op.drop_constraint', 'op.drop_constraint', (), '', False, 'from alembic import op\n'), ((62, 4, 62, 47), 'alembic.op.drop_column', 'op.drop_column', ({(62, 19, 62, 24): '"""job"""', (62, 26, 62, 46): '"""file_generation_id"""'}, {}), "('job', 'file_generation_id')", False, 'from alembic import op\n'), ((69, 4, 69, 36), 'alembic.op.drop_table', 'op.drop_table', ({(69, 18, 69, 35): '"""file_generation"""'}, {}), "('file_generation')", False, 'from alembic import op\n'), ((70, 4, 72, 8), 'alembic.op.execute', 'op.execute', ({(70, 15, 72, 7): '"""\n        DROP TYPE generation_agency_types\n    """'}, {}), '("""\n        DROP TYPE generation_agency_types\n    """)', False, 'from alembic import op\n'), ((73, 4, 75, 8), 'alembic.op.execute', 'op.execute', ({(73, 15, 75, 7): '"""\n        DROP TYPE generation_file_types\n    """'}, {}), '("""\n        DROP TYPE generation_file_types\n    """)', False, 'from alembic import op\n'), ((44, 4, 44, 49), 'sqlalchemy.PrimaryKeyConstraint', 'sa.PrimaryKeyConstraint', ({(44, 28, 44, 48): '"""file_generation_id"""'}, {}), "('file_generation_id')", True, 'import sqlalchemy as sa\n'), ((46, 20, 46, 58), 'alembic.op.f', 'op.f', ({(46, 25, 46, 57): '"""ix_file_generation_agency_code"""'}, {}), "('ix_file_generation_agency_code')", False, 'from alembic import op\n'), ((47, 20, 47, 58), 'alembic.op.f', 'op.f', ({(47, 25, 47, 57): '"""ix_file_generation_agency_type"""'}, {}), "('ix_file_generation_agency_type')", False, 'from alembic import op\n'), ((48, 20, 48, 55), 'alembic.op.f', 'op.f', ({(48, 25, 48, 54): '"""ix_file_generation_end_date"""'}, {}), "('ix_file_generation_end_date')", False, 'from alembic import op\n'), ((49, 20, 49, 56), 'alembic.op.f', 'op.f', ({(49, 25, 49, 55): '"""ix_file_generation_file_type"""'}, {}), "('ix_file_generation_file_type')", False, 'from alembic import op\n'), ((50, 20, 50, 59), 'alembic.op.f', 'op.f', ({(50, 25, 50, 58): '"""ix_file_generation_request_date"""'}, {}), "('ix_file_generation_request_date')", False, 'from alembic import op\n'), ((51, 20, 51, 57), 'alembic.op.f', 'op.f', ({(51, 25, 51, 56): '"""ix_file_generation_start_date"""'}, {}), "('ix_file_generation_start_date')", False, 'from alembic import op\n'), ((63, 18, 63, 55), 'alembic.op.f', 'op.f', ({(63, 23, 63, 54): '"""ix_file_generation_start_date"""'}, {}), "('ix_file_generation_start_date')", False, 'from alembic import op\n'), ((64, 18, 64, 57), 'alembic.op.f', 'op.f', ({(64, 23, 64, 56): '"""ix_file_generation_request_date"""'}, {}), "('ix_file_generation_request_date')", False, 'from alembic import op\n'), ((65, 18, 65, 54), 'alembic.op.f', 'op.f', ({(65, 23, 65, 53): '"""ix_file_generation_file_type"""'}, {}), "('ix_file_generation_file_type')", False, 'from alembic import op\n'), ((66, 18, 66, 53), 'alembic.op.f', 'op.f', ({(66, 23, 66, 52): '"""ix_file_generation_end_date"""'}, {}), "('ix_file_generation_end_date')", False, 'from alembic import op\n'), ((67, 18, 67, 56), 'alembic.op.f', 'op.f', ({(67, 23, 67, 55): '"""ix_file_generation_agency_type"""'}, {}), "('ix_file_generation_agency_type')", False, 'from alembic import op\n'), ((68, 18, 68, 56), 'alembic.op.f', 'op.f', ({(68, 23, 68, 55): '"""ix_file_generation_agency_code"""'}, {}), "('ix_file_generation_agency_code')", False, 'from alembic import op\n'), ((33, 28, 33, 41), 'sqlalchemy.DateTime', 'sa.DateTime', ({}, {}), '()', True, 'import sqlalchemy as sa\n'), ((34, 28, 34, 41), 'sqlalchemy.DateTime', 'sa.DateTime', ({}, {}), '()', True, 'import sqlalchemy as sa\n'), ((35, 36, 35, 48), 'sqlalchemy.Integer', 'sa.Integer', ({}, {}), '()', True, 'import sqlalchemy as sa\n'), ((36, 30, 36, 39), 'sqlalchemy.Date', 'sa.Date', ({}, {}), '()', True, 'import sqlalchemy as sa\n'), ((37, 28, 37, 37), 'sqlalchemy.Date', 'sa.Date', ({}, {}), '()', True, 'import sqlalchemy as sa\n'), ((38, 26, 38, 35), 'sqlalchemy.Date', 'sa.Date', ({}, {}), '()', True, 'import sqlalchemy as sa\n'), ((39, 29, 39, 38), 'sqlalchemy.Text', 'sa.Text', ({}, {}), '()', True, 'import sqlalchemy as sa\n'), ((40, 29, 40, 91), 'sqlalchemy.Enum', 'sa.Enum', (), '', True, 'import sqlalchemy as sa\n'), ((41, 27, 41, 76), 'sqlalchemy.Enum', 'sa.Enum', (), '', True, 'import sqlalchemy as sa\n'), ((42, 27, 42, 36), 'sqlalchemy.Text', 'sa.Text', ({}, {}), '()', True, 'import sqlalchemy as sa\n'), ((43, 32, 43, 44), 'sqlalchemy.Boolean', 'sa.Boolean', ({}, {}), '()', True, 'import sqlalchemy as sa\n'), ((52, 57, 52, 69), 'sqlalchemy.Integer', 'sa.Integer', ({}, {}), '()', True, 'import sqlalchemy as sa\n'), ((60, 50, 60, 62), 'sqlalchemy.BOOLEAN', 'sa.BOOLEAN', ({}, {}), '()', True, 'import sqlalchemy as sa\n'), ((60, 79, 60, 95), 'sqlalchemy.text', 'sa.text', ({(60, 87, 60, 94): '"""false"""'}, {}), "('false')", True, 'import sqlalchemy as sa\n')]