"""add file format to file generation table

Revision ID: 3c16b4d8506c
Revises: 0a36baf32413
Create Date: 2019-07-23 14:02:47.454725

"""

# revision identifiers, used by Alembic.
revision = '3c16b4d8506c'
down_revision = '0a36baf32413'
branch_labels = None
depends_on = None

from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql

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! ###
    generation_file_formats = postgresql.ENUM('csv', 'txt', name='generation_file_formats')
    generation_file_formats.create(op.get_bind())
    op.add_column('file_generation', sa.Column('file_format', sa.Enum('csv', 'txt', name='generation_file_formats'), server_default='csv', nullable=True))
    op.execute("""
            UPDATE file_generation
            SET file_format = 'csv'
        """)
    op.alter_column('file_generation', 'file_format', nullable=False)
    op.create_index(op.f('ix_file_generation_file_format'), 'file_generation', ['file_format'], unique=False)
    # ### end Alembic commands ###


def downgrade_data_broker():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index(op.f('ix_file_generation_file_format'), table_name='file_generation')
    op.drop_column('file_generation', 'file_format')
    op.execute("""
            DROP TYPE generation_file_formats
        """)
    op.execute("""
            UPDATE file_generation
            SET is_cached_file = False
        """)
    # ### end Alembic commands ###

