"""Add ``version`` column to ``codal_statements``. Revision ID: 0026"""

from __future__ import annotations

from repo_core.migrations.builder import MigrationBuilder
from repo_core.migrations.runner import Migration

VERSION = "0026"


def get_postgres_migrations() -> list[Migration]:
    return [
        Migration(
            version="codal_statements_0006",
            description=(
                "Add version column to codal_statements and make URL uniqueness version-aware"
            ),
            up=(
                MigrationBuilder("codal_statements")
                .add_column("version", "INTEGER", nullable=False, default=1)
                .drop_index("uq_codal_statements_url")
                .add_index(["url", "version"], unique=True)
                .alter_table()
            ),
            down=(
                MigrationBuilder("codal_statements")
                .drop_index("uq_codal_statements_url_version")
                .add_index(["url"], unique=True)
                .drop_column("version")
                .alter_table()
            ),
        ),
    ]