"""box_plot

Revision ID: 13b676178b08
Revises: cfacecb61ac1
Create Date: 2019-04-16 21:55:10.723443

"""
from alembic import op
from sqlalchemy import String, Integer
from sqlalchemy.sql import table, column, text
from caipirinha.migration_utils import get_enable_disable_fk_command

# revision identifiers, used by Alembic.
revision = '13b676178b08'
down_revision = 'cfacecb61ac1'
branch_labels = None
depends_on = None


def insert_visualization_type():
    tb = table(
        'visualization_type',
        column('id', Integer),
        column('name', String),
        column('help', String),
        column('icon', String))

    all_ops = [
        (123, 'box-plot', 'Box plot', 'fa-chart'),
        (124, 'histogram', 'Histogram', 'fa-chart'),
    ]
    rows = [dict(zip([c.name for c in tb.columns], operation)) for operation in
            all_ops]

    op.bulk_insert(tb, rows)


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    try:
        op.execute(text('BEGIN'))
        insert_visualization_type()
        op.execute(text('COMMIT'))
    except:
        op.execute(text('ROLLBACK'))
        raise


# noinspection PyBroadException
def downgrade():
    try:
        op.execute(text('BEGIN'))
        op.execute(text(get_enable_disable_fk_command(False)))
        op.execute(
            text("DELETE FROM visualization_type WHERE id IN (123, 124)"))
        op.execute(text(get_enable_disable_fk_command(True)))
        op.execute(text('COMMIT'))
    except:
        op.execute(text('ROLLBACK'))
        raise
