"""create_item_order_modes

Revision ID: a0b8a3c20bbd
Revises: d6ce18d761a3
Create Date: 2020-02-05 17:24:21.519000

"""
import logging

from alembic import op
import sqlalchemy as sa

logger = logging.getLogger(__name__)

# revision identifiers, used by Alembic.
revision = 'a0b8a3c20bbd'
down_revision = 'd6ce18d761a3'
branch_labels = None
depends_on = None

first_agent_version = '20.3.4'


def upgrade():
    connection = op.get_bind()
    inspector = sa.inspect(connection)
    tables = set(inspector.get_table_names())
    if 'item_order_modes' in tables:
        logger.info("Table 'item_order_modes' already exists. Skipping its migration...")
        return

    op.create_table(
        'item_order_modes',
        sa.Column('name', sa.String(length=128), nullable=True),
        sa.Column('available', sa.Boolean()),
        sa.Column('pos_id', sa.String(length=64), nullable=True),
        sa.Column('id', sa.String(length=64), nullable=False),
    )


def downgrade():
    op.drop_table('item_order_modes')
