"""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 ###


[((2185, 2347), '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"""'}), "('fk_file_request_file_generation_id', 'job',\n    'file_generation', ['file_generation_id'], ['file_generation_id'],\n    ondelete='SET NULL')\n", (2206, 2347), False, 'from alembic import op\n'), ((2344, 2380), 'alembic.op.drop_column', 'op.drop_column', (['"""job"""', '"""from_cached"""'], {}), "('job', 'from_cached')\n", (2358, 2380), False, 'from alembic import op\n'), ((2652, 2740), 'alembic.op.drop_constraint', 'op.drop_constraint', (['"""fk_file_request_file_generation_id"""', '"""job"""'], {'type_': '"""foreignkey"""'}), "('fk_file_request_file_generation_id', 'job', type_=\n    'foreignkey')\n", (2670, 2740), False, 'from alembic import op\n'), ((2740, 2783), 'alembic.op.drop_column', 'op.drop_column', (['"""job"""', '"""file_generation_id"""'], {}), "('job', 'file_generation_id')\n", (2754, 2783), False, 'from alembic import op\n'), ((3311, 3343), 'alembic.op.drop_table', 'op.drop_table', (['"""file_generation"""'], {}), "('file_generation')\n", (3324, 3343), False, 'from alembic import op\n'), ((3348, 3413), 'alembic.op.execute', 'op.execute', (['"""\n        DROP TYPE generation_agency_types\n    """'], {}), '("""\n        DROP TYPE generation_agency_types\n    """)\n', (3358, 3413), False, 'from alembic import op\n'), ((3418, 3481), 'alembic.op.execute', 'op.execute', (['"""\n        DROP TYPE generation_file_types\n    """'], {}), '("""\n        DROP TYPE generation_file_types\n    """)\n', (3428, 3481), False, 'from alembic import op\n'), ((1392, 1437), 'sqlalchemy.PrimaryKeyConstraint', 'sa.PrimaryKeyConstraint', (['"""file_generation_id"""'], {}), "('file_generation_id')\n", (1415, 1437), True, 'import sqlalchemy as sa\n'), ((1464, 1502), 'alembic.op.f', 'op.f', (['"""ix_file_generation_agency_code"""'], {}), "('ix_file_generation_agency_code')\n", (1468, 1502), False, 'from alembic import op\n'), ((1574, 1612), 'alembic.op.f', 'op.f', (['"""ix_file_generation_agency_type"""'], {}), "('ix_file_generation_agency_type')\n", (1578, 1612), False, 'from alembic import op\n'), ((1684, 1719), 'alembic.op.f', 'op.f', (['"""ix_file_generation_end_date"""'], {}), "('ix_file_generation_end_date')\n", (1688, 1719), False, 'from alembic import op\n'), ((1788, 1824), 'alembic.op.f', 'op.f', (['"""ix_file_generation_file_type"""'], {}), "('ix_file_generation_file_type')\n", (1792, 1824), False, 'from alembic import op\n'), ((1894, 1933), 'alembic.op.f', 'op.f', (['"""ix_file_generation_request_date"""'], {}), "('ix_file_generation_request_date')\n", (1898, 1933), False, 'from alembic import op\n'), ((2006, 2043), 'alembic.op.f', 'op.f', (['"""ix_file_generation_start_date"""'], {}), "('ix_file_generation_start_date')\n", (2010, 2043), False, 'from alembic import op\n'), ((2802, 2839), 'alembic.op.f', 'op.f', (['"""ix_file_generation_start_date"""'], {}), "('ix_file_generation_start_date')\n", (2806, 2839), False, 'from alembic import op\n'), ((2889, 2928), 'alembic.op.f', 'op.f', (['"""ix_file_generation_request_date"""'], {}), "('ix_file_generation_request_date')\n", (2893, 2928), False, 'from alembic import op\n'), ((2978, 3014), 'alembic.op.f', 'op.f', (['"""ix_file_generation_file_type"""'], {}), "('ix_file_generation_file_type')\n", (2982, 3014), False, 'from alembic import op\n'), ((3064, 3099), 'alembic.op.f', 'op.f', (['"""ix_file_generation_end_date"""'], {}), "('ix_file_generation_end_date')\n", (3068, 3099), False, 'from alembic import op\n'), ((3149, 3187), 'alembic.op.f', 'op.f', (['"""ix_file_generation_agency_type"""'], {}), "('ix_file_generation_agency_type')\n", (3153, 3187), False, 'from alembic import op\n'), ((3237, 3275), 'alembic.op.f', 'op.f', (['"""ix_file_generation_agency_code"""'], {}), "('ix_file_generation_agency_code')\n", (3241, 3275), False, 'from alembic import op\n'), ((636, 649), 'sqlalchemy.DateTime', 'sa.DateTime', ([], {}), '()\n', (647, 649), True, 'import sqlalchemy as sa\n'), ((695, 708), 'sqlalchemy.DateTime', 'sa.DateTime', ([], {}), '()\n', (706, 708), True, 'import sqlalchemy as sa\n'), ((762, 774), 'sqlalchemy.Integer', 'sa.Integer', ([], {}), '()\n', (772, 774), True, 'import sqlalchemy as sa\n'), ((823, 832), 'sqlalchemy.Date', 'sa.Date', ([], {}), '()\n', (830, 832), True, 'import sqlalchemy as sa\n'), ((879, 888), 'sqlalchemy.Date', 'sa.Date', ([], {}), '()\n', (886, 888), True, 'import sqlalchemy as sa\n'), ((933, 942), 'sqlalchemy.Date', 'sa.Date', ([], {}), '()\n', (940, 942), True, 'import sqlalchemy as sa\n'), ((990, 999), 'sqlalchemy.Text', 'sa.Text', ([], {}), '()\n', (997, 999), True, 'import sqlalchemy as sa\n'), ((1047, 1109), 'sqlalchemy.Enum', 'sa.Enum', (['"""awarding"""', '"""funding"""'], {'name': '"""generation_agency_types"""'}), "('awarding', 'funding', name='generation_agency_types')\n", (1054, 1109), True, 'import sqlalchemy as sa\n'), ((1182, 1231), 'sqlalchemy.Enum', 'sa.Enum', (['"""D1"""', '"""D2"""'], {'name': '"""generation_file_types"""'}), "('D1', 'D2', name='generation_file_types')\n", (1189, 1231), True, 'import sqlalchemy as sa\n'), ((1298, 1307), 'sqlalchemy.Text', 'sa.Text', ([], {}), '()\n', (1305, 1307), True, 'import sqlalchemy as sa\n'), ((1357, 1369), 'sqlalchemy.Boolean', 'sa.Boolean', ([], {}), '()\n', (1367, 1369), True, 'import sqlalchemy as sa\n'), ((2151, 2163), 'sqlalchemy.Integer', 'sa.Integer', ([], {}), '()\n', (2161, 2163), True, 'import sqlalchemy as sa\n'), ((2563, 2575), 'sqlalchemy.BOOLEAN', 'sa.BOOLEAN', ([], {}), '()\n', (2573, 2575), True, 'import sqlalchemy as sa\n'), ((2592, 2608), 'sqlalchemy.text', 'sa.text', (['"""false"""'], {}), "('false')\n", (2599, 2608), True, 'import sqlalchemy as sa\n')]