"""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, 'alembic.op.create_foreign_key', 'op.create_foreign_key', (['"""fk_file_request_file_generation_id"""', '"""job"""', '"""file_generation"""', "['file_generation_id']", "['file_generation_id']"], {'ondelete': '"""SET NULL"""'}), False, 'from alembic import op\n'), (54, 'alembic.op.drop_column', 'op.drop_column', (['"""job"""', '"""from_cached"""'], {}), False, 'from alembic import op\n'), (61, 'alembic.op.drop_constraint', 'op.drop_constraint', (['"""fk_file_request_file_generation_id"""', '"""job"""'], {'type_': '"""foreignkey"""'}), False, 'from alembic import op\n'), (62, 'alembic.op.drop_column', 'op.drop_column', (['"""job"""', '"""file_generation_id"""'], {}), False, 'from alembic import op\n'), (69, 'alembic.op.drop_table', 'op.drop_table', (['"""file_generation"""'], {}), False, 'from alembic import op\n'), (70, 'alembic.op.execute', 'op.execute', (['"""\n        DROP TYPE generation_agency_types\n    """'], {}), False, 'from alembic import op\n'), (73, 'alembic.op.execute', 'op.execute', (['"""\n        DROP TYPE generation_file_types\n    """'], {}), False, 'from alembic import op\n'), (44, 'sqlalchemy.PrimaryKeyConstraint', 'sa.PrimaryKeyConstraint', (['"""file_generation_id"""'], {}), True, 'import sqlalchemy as sa\n'), (46, 'alembic.op.f', 'op.f', (['"""ix_file_generation_agency_code"""'], {}), False, 'from alembic import op\n'), (47, 'alembic.op.f', 'op.f', (['"""ix_file_generation_agency_type"""'], {}), False, 'from alembic import op\n'), (48, 'alembic.op.f', 'op.f', (['"""ix_file_generation_end_date"""'], {}), False, 'from alembic import op\n'), (49, 'alembic.op.f', 'op.f', (['"""ix_file_generation_file_type"""'], {}), False, 'from alembic import op\n'), (50, 'alembic.op.f', 'op.f', (['"""ix_file_generation_request_date"""'], {}), False, 'from alembic import op\n'), (51, 'alembic.op.f', 'op.f', (['"""ix_file_generation_start_date"""'], {}), False, 'from alembic import op\n'), (63, 'alembic.op.f', 'op.f', (['"""ix_file_generation_start_date"""'], {}), False, 'from alembic import op\n'), (64, 'alembic.op.f', 'op.f', (['"""ix_file_generation_request_date"""'], {}), False, 'from alembic import op\n'), (65, 'alembic.op.f', 'op.f', (['"""ix_file_generation_file_type"""'], {}), False, 'from alembic import op\n'), (66, 'alembic.op.f', 'op.f', (['"""ix_file_generation_end_date"""'], {}), False, 'from alembic import op\n'), (67, 'alembic.op.f', 'op.f', (['"""ix_file_generation_agency_type"""'], {}), False, 'from alembic import op\n'), (68, 'alembic.op.f', 'op.f', (['"""ix_file_generation_agency_code"""'], {}), False, 'from alembic import op\n'), (33, 'sqlalchemy.DateTime', 'sa.DateTime', ([], {}), True, 'import sqlalchemy as sa\n'), (34, 'sqlalchemy.DateTime', 'sa.DateTime', ([], {}), True, 'import sqlalchemy as sa\n'), (35, 'sqlalchemy.Integer', 'sa.Integer', ([], {}), True, 'import sqlalchemy as sa\n'), (36, 'sqlalchemy.Date', 'sa.Date', ([], {}), True, 'import sqlalchemy as sa\n'), (37, 'sqlalchemy.Date', 'sa.Date', ([], {}), True, 'import sqlalchemy as sa\n'), (38, 'sqlalchemy.Date', 'sa.Date', ([], {}), True, 'import sqlalchemy as sa\n'), (39, 'sqlalchemy.Text', 'sa.Text', ([], {}), True, 'import sqlalchemy as sa\n'), (40, 'sqlalchemy.Enum', 'sa.Enum', (['"""awarding"""', '"""funding"""'], {'name': '"""generation_agency_types"""'}), True, 'import sqlalchemy as sa\n'), (41, 'sqlalchemy.Enum', 'sa.Enum', (['"""D1"""', '"""D2"""'], {'name': '"""generation_file_types"""'}), True, 'import sqlalchemy as sa\n'), (42, 'sqlalchemy.Text', 'sa.Text', ([], {}), True, 'import sqlalchemy as sa\n'), (43, 'sqlalchemy.Boolean', 'sa.Boolean', ([], {}), True, 'import sqlalchemy as sa\n'), (52, 'sqlalchemy.Integer', 'sa.Integer', ([], {}), True, 'import sqlalchemy as sa\n'), (60, 'sqlalchemy.BOOLEAN', 'sa.BOOLEAN', ([], {}), True, 'import sqlalchemy as sa\n'), (60, 'sqlalchemy.text', 'sa.text', (['"""false"""'], {}), True, 'import sqlalchemy as sa\n')]