""" Create global_list table that stores
manual inclusions and exclusions of annotations from all files

Revision ID: 9118d3b6dba2
Revises: <PASSWORD>
Create Date: 2020-08-07 12:17:34.920981

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

# revision identifiers, used by Alembic.
revision = '9118d3b6dba2'
down_revision = '<PASSWORD>'
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        'global_list',
        sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
        sa.Column('annotation', postgresql.JSON(astext_type=sa.Text()), nullable=False),
        sa.Column('type', sa.String(length=12), nullable=False),
        sa.Column('file_id', sa.Integer(), nullable=False, index=True),
        sa.Column('reviewed', sa.Boolean(), default=False),
        sa.Column('approved', sa.Boolean(), default=False),
        sa.ForeignKeyConstraint(['file_id'], ['files_content.id'], name=op.f('fk_global_list_file_id_files_content')),
        sa.PrimaryKeyConstraint('id', name=op.f('pk_global_list'))
    )
    # ### end Alembic commands ###
    if context.get_x_argument(as_dictionary=True).get('data_migrate', None):
        data_upgrades()


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_table('global_list')
    # ### end Alembic commands ###
    # NOTE: In practice perfect downgrades are difficult and in some cases
    # impossible! It is more practical to use database backups/snapshots to
    # "downgrade" the database. Changes to the database that we intend to
    # push to production should always be added to a NEW migration.
    # (i.e. "downgrade forward"!)


def data_upgrades():
    """Add optional data upgrade migrations here"""
    pass


def data_downgrades():
    """Add optional data downgrade migrations here"""
    pass
