"""add amount to held ticket service charge

Revision ID: 281cea12023f
Revises: bdbcca2c4ba0d5
Create Date: 2019-03-18 18:56:59.623000

"""
from alembic import op
from sqlalchemy import Column, Integer


# revision identifiers, used by Alembic.
revision = '281cea12023f'
down_revision = 'bdbcca2c4ba0d5'
branch_labels = None
depends_on = None

# TODO: Set the first_agent_version correctly before merging this revision
first_agent_version = '19.4.3'


def upgrade():
    """
    Use batch-operations to support sqlite

    > with op.batch_alter_table('table_name') as batch_op:
    >     pass
    """
    connection = op.get_bind()
    try:
        connection.execute('PRAGMA foreign_keys = "0";')

        with op.batch_alter_table('held_ticket_service_charges') as batch_op:
            batch_op.add_column(Column('amount', Integer, nullable=True))

    finally:
        connection.execute('PRAGMA foreign_keys = "1";')


def downgrade():
    """
    Use batch-operations to support sqlite

    > with op.batch_alter_table('table_name') as batch_op:
    >     pass
    """
    connection = op.get_bind()
    try:
        connection.execute('PRAGMA foreign_keys = "0";')

        with op.batch_alter_table('held_ticket_service_charges') as batch_op:
            batch_op.drop_column('amount')

    finally:
        connection.execute('PRAGMA foreign_keys = "1";')
