"""add_retest_fields

Revision ID: b016retests
Revises: b015snapshots
Create Date: 2026-02-10 01:00:00.000000

"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql

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


def upgrade() -> None:
    op.add_column(
        "tests",
        sa.Column(
            "retest_of",
            postgresql.UUID(as_uuid=True),
            sa.ForeignKey("tests.id"),
            nullable=True,
        ),
    )
    op.add_column(
        "tests",
        sa.Column("retest_count", sa.Integer, server_default="0", nullable=False),
    )
    op.create_index("ix_tests_retest_of", "tests", ["retest_of"])


def downgrade() -> None:
    op.drop_index("ix_tests_retest_of", table_name="tests")
    op.drop_column("tests", "retest_count")
    op.drop_column("tests", "retest_of")
