"""add_declared_tips_to_clock_entry

Revision ID: 972dcd13ed21
Revises: e0cd4ca3926c
Create Date: 2019-01-30 11:51:34.067000

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

revision = '972dcd13ed21'
down_revision = 'e0cd4ca3926c'
branch_labels = None
depends_on = None

first_agent_version = '19.2.5'


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('clock_entries') as batch_op:
            batch_op.add_column(Column('declared_tips', 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('clock_entries') as batch_op:
            batch_op.drop_column('declared_tips')

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