"""Inclusive taxes

Revision ID: b451ab2b9136
Revises: 6ce2245413b5
Create Date: 2019-12-16 15:29:58.901000

"""
from alembic import op

# revision identifiers, used by Alembic.
from sqlalchemy import Column, Integer

revision = 'b451ab2b9136'
down_revision = '6ce2245413b5'
branch_labels = None
depends_on = None

first_agent_version = '20.1.15'


def upgrade():
    connection = op.get_bind()
    try:
        connection.execute('PRAGMA foreign_keys = "0";')

        with op.batch_alter_table('ticket_totals') as batch_op:
            batch_op.add_column(Column('inclusive_tax', Integer(), nullable=True))
            batch_op.add_column(Column('exclusive_tax', Integer(), nullable=True))

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

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

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

        with op.batch_alter_table('held_ticket_totals') as batch_op:
            batch_op.add_column(Column('inclusive_tax', Integer(), nullable=True))
            batch_op.add_column(Column('exclusive_tax', Integer(), nullable=True))

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

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

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

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


def downgrade():
    connection = op.get_bind()
    try:
        connection.execute('PRAGMA foreign_keys = "0";')

        with op.batch_alter_table('ticket_totals') as batch_op:
            batch_op.drop_column('inclusive_tax')
            batch_op.drop_column('exclusive_tax')

        with op.batch_alter_table('ticket_items') as batch_op:
            batch_op.drop_column('included_tax')

        with op.batch_alter_table('ticket_combos') as batch_op:
            batch_op.drop_column('included_tax')

        with op.batch_alter_table('ticket_service_charges') as batch_op:
            batch_op.drop_column('included_tax')

        with op.batch_alter_table('held_ticket_totals') as batch_op:
            batch_op.drop_column('inclusive_tax')
            batch_op.drop_column('exclusive_tax')

        with op.batch_alter_table('held_ticket_items') as batch_op:
            batch_op.drop_column('included_tax')

        with op.batch_alter_table('held_ticket_combos') as batch_op:
            batch_op.drop_column('included_tax')

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

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

