"""add alternative class parameters to WMS geodata

Revision ID: 4ca4e5e44ff2
Revises: 2ce65db29472
Create Date: 2024-12-09 17:18:21.148120

"""

import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision = "4ca4e5e44ff2"
down_revision = "2ce65db29472"
branch_labels = None
depends_on = None


def upgrade():
    op.execute(
        "DELETE FROM geo_feature WHERE id in "
        "(SELECT id FROM feature WHERE data_id IS NULL)"
    )
    op.execute("DELETE FROM feature WHERE data_id IS NULL")
    with op.batch_alter_table("feature", schema=None) as batch_op:
        batch_op.alter_column(
            "data_id", existing_type=sa.INTEGER(), nullable=False
        )

    with op.batch_alter_table("wms_geo_data", schema=None) as batch_op:
        batch_op.add_column(sa.Column("start", sa.Float(), nullable=True))
        batch_op.add_column(sa.Column("step", sa.Float(), nullable=True))
        batch_op.add_column(sa.Column("stop", sa.Float(), nullable=True))


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    with op.batch_alter_table("wms_geo_data", schema=None) as batch_op:
        batch_op.drop_column("stop")
        batch_op.drop_column("step")
        batch_op.drop_column("start")

    with op.batch_alter_table("feature", schema=None) as batch_op:
        batch_op.alter_column(
            "data_id", existing_type=sa.INTEGER(), nullable=True
        )

    # ### end Alembic commands ###
