"""add maintenance tree type

Revision ID: 0f1ca2af3647
Revises: 039
Create Date: 2026-02-17 10:25:54.959861

"""
from typing import Sequence, Union

from alembic import op

# revision identifiers, used by Alembic.
revision: str = '0f1ca2af3647'
down_revision: Union[str, None] = '039'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    op.execute("ALTER TABLE trees DROP CONSTRAINT ck_trees_tree_type")
    op.execute(
        "ALTER TABLE trees ADD CONSTRAINT ck_trees_tree_type "
        "CHECK (tree_type IN ('troubleshooting', 'procedural', 'maintenance'))"
    )


def downgrade() -> None:
    op.execute("UPDATE trees SET tree_type = 'procedural' WHERE tree_type = 'maintenance'")
    op.execute("ALTER TABLE trees DROP CONSTRAINT ck_trees_tree_type")
    op.execute(
        "ALTER TABLE trees ADD CONSTRAINT ck_trees_tree_type "
        "CHECK (tree_type IN ('troubleshooting', 'procedural'))"
    )
