"""Removed Node and Conn

Peek Plugin Database Migration Script

Revision ID: 2c5f47322bda
Revises: d6e25d8ba156
Create Date: 2017-08-24 12:58:59.016532

"""

# revision identifiers, used by Alembic.
revision = "2c5f47322bda"
down_revision = "d6e25d8ba156"
branch_labels = None
depends_on = None

from alembic import op
import sqlalchemy as sa
import geoalchemy2


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_table("DispPolylineConn", schema="pl_diagram")
    op.drop_table("DispGroupPointerNode", schema="pl_diagram")
    op.drop_table("ModelConn", schema="pl_diagram")
    op.drop_table("ModelNode", schema="pl_diagram")
    op.drop_table("DispAction", schema="pl_diagram")
    op.drop_table("ModelNodeType", schema="pl_diagram")
    op.drop_table("ModelConnType", schema="pl_diagram")

    op.add_column(
        "DispBase",
        sa.Column("key", sa.String(length=50), nullable=True),
        schema="pl_diagram",
    )
    op.add_column(
        "DispBase",
        sa.Column("selectable", sa.Boolean(), server_default="0", nullable=False),
        schema="pl_diagram",
    )

    op.add_column(
        "ModelSet",
        sa.Column("key", sa.String(length=50), nullable=True),
        schema="pl_diagram",
    )
    op.execute(""" UPDATE "pl_diagram"."ModelSet" SET "key" = "name" """)
    op.alter_column(
        "ModelSet",
        "key",
        type_=sa.String(length=50),
        nullable=False,
        schema="pl_diagram",
    )

    # ### end Alembic commands ###


def downgrade():
    raise NotImplementedError("Downgrade is not implemented")
