"""Add Held Discount Code

Revision ID: 8d73e2e0ae6d
Revises: af3a34c8a412
Create Date: 2021-12-20 16:28:10.051000

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '8d73e2e0ae6d'
down_revision = 'af3a34c8a412'
branch_labels = None
depends_on = None

first_agent_version = '21.12.21'


def upgrade():
    connection = op.get_bind()
    try:
        connection.execute('PRAGMA foreign_keys = "0";')
        connection.execute(
            "ALTER TABLE held_ticket_discounts ADD code VARCHAR(128);"
        )
        connection.execute(
            "ALTER TABLE held_ticket_item_discounts ADD code VARCHAR(128);"
        )
    finally:
        connection.execute('PRAGMA foreign_keys = "1";')


def downgrade():
    connection = op.get_bind()
    try:
        connection.execute('PRAGMA foreign_keys = "0";')
        connection.execute('ALTER TABLE held_ticket_discounts DROP COLUMN "code";')
        connection.execute('ALTER TABLE held_ticket_item_discounts DROP COLUMN "code";')
    finally:
        connection.execute('PRAGMA foreign_keys = "1";')
