"""v0.12.5 migration

Revision ID: 72e2079576d3
Revises: bd59252fe91f
Create Date: 2025-06-27 15:08:18.902296

"""

from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa
from sqlalchemy.engine.reflection import Inspector

# revision identifiers, used by Alembic.
revision: str = "72e2079576d3"
down_revision: Union[str, None] = "bd59252fe91f"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    # Get database connection and inspect constraints
    conn = op.get_bind()
    inspector = Inspector.from_engine(conn)

    # Inspect constraints on the 'health_data' table
    constraints_health_data = inspector.get_unique_constraints("health_data")
    for constraint in constraints_health_data:
        if constraint["name"] == "health_data_date_key":
            op.drop_constraint(constraint["name"], "health_data", type_="unique")
            break

    op.alter_column(
        "server_settings",
        "units",
        existing_type=sa.INTEGER(),
        comment="User units (one digit)(1 - metric, 2 - imperial)",
        existing_comment="Units (one digit)(1 - metric, 2 - imperial)",
        existing_nullable=False,
    )
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.alter_column(
        "server_settings",
        "units",
        existing_type=sa.INTEGER(),
        comment="Units (one digit)(1 - metric, 2 - imperial)",
        existing_comment="User units (one digit)(1 - metric, 2 - imperial)",
        existing_nullable=False,
    )
    op.create_unique_constraint(op.f("health_data_date_key"), "health_data", ["date"])
    # ### end Alembic commands ###
