"""updated series_index to float and added UniqueConstraint to audiobook and audiobook_author.

Revision ID: b3c60cc5beb5
Revises: d7864d1ffc17
Create Date: 2026-06-10 20:02:43.073725

"""

from __future__ import annotations

from typing import TYPE_CHECKING

import sqlalchemy as sa
from alembic import op

from python.orm import RichieBase

if TYPE_CHECKING:
    from collections.abc import Sequence

# revision identifiers, used by Alembic.
revision: str = "b3c60cc5beb5"
down_revision: str | None = "d7864d1ffc17"
branch_labels: str | Sequence[str] | None = None
depends_on: str | Sequence[str] | None = None

schema = RichieBase.schema_name


def upgrade() -> None:
    """Upgrade."""
    # ### commands auto generated by Alembic - please adjust! ###
    op.alter_column(
        "audiobook",
        "series_index",
        existing_type=sa.INTEGER(),
        type_=sa.Float(),
        existing_nullable=False,
        schema=schema,
    )
    op.create_unique_constraint(
        op.f("uq_audiobook_author_id"),
        "audiobook",
        ["author_id", "series_id", "title"],
        schema=schema,
        postgresql_nulls_not_distinct=True,
    )
    # ### end Alembic commands ###


def downgrade() -> None:
    """Downgrade."""
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_constraint(op.f("uq_audiobook_author_id"), "audiobook", schema=schema, type_="unique")
    op.alter_column(
        "audiobook",
        "series_index",
        existing_type=sa.Float(),
        type_=sa.INTEGER(),
        existing_nullable=False,
        schema=schema,
    )
    # ### end Alembic commands ###
