"""Add ``version`` and ``raw_hash`` columns to all codal_publisher_* tables.
Revision ID: 0028"""

from __future__ import annotations

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

VERSION = "0028"


def get_postgres_migrations() -> list[Migration]:
    return [
        # ── codal_publishers ────────────────────────────────────────
        Migration(
            version="codal_publishers_0005",
            description="Add version, raw_hash to codal_publishers; add id UUID PK",
            up=(
                MigrationBuilder("codal_publishers")
                .add_column("version", "INTEGER", nullable=False, default=1)
                .add_column("raw_hash", "TEXT", nullable=True)
                .alter_table()
            ),
            down=(
                MigrationBuilder("codal_publishers")
                .drop_column("version")
                .drop_column("raw_hash")
                .alter_table()
            ),
        ),
        # ── codal_publisher_details ─────────────────────────────────
        Migration(
            version="codal_publisher_details_0003",
            description="Add version, raw_hash to codal_publisher_details",
            up=(
                MigrationBuilder("codal_publisher_details")
                .add_column("version", "INTEGER", nullable=False, default=1)
                .add_column("raw_hash", "TEXT", nullable=True)
                .alter_table()
            ),
            down=(
                MigrationBuilder("codal_publisher_details")
                .drop_column("version")
                .drop_column("raw_hash")
                .alter_table()
            ),
        ),
        # ── codal_publisher_contacts ────────────────────────────────
        Migration(
            version="codal_publisher_contacts_0002",
            description="Add version, raw_hash to codal_publisher_contacts",
            up=(
                MigrationBuilder("codal_publisher_contacts")
                .add_column("version", "INTEGER", nullable=False, default=1)
                .add_column("raw_hash", "TEXT", nullable=True)
                .alter_table()
            ),
            down=(
                MigrationBuilder("codal_publisher_contacts")
                .drop_column("version")
                .drop_column("raw_hash")
                .alter_table()
            ),
        ),
        # ── codal_publisher_board ───────────────────────────────────
        Migration(
            version="codal_publisher_board_0002",
            description="Add version, raw_hash to codal_publisher_board",
            up=(
                MigrationBuilder("codal_publisher_board")
                .add_column("version", "INTEGER", nullable=False, default=1)
                .add_column("raw_hash", "TEXT", nullable=True)
                .alter_table()
            ),
            down=(
                MigrationBuilder("codal_publisher_board")
                .drop_column("version")
                .drop_column("raw_hash")
                .alter_table()
            ),
        ),
        # ── codal_publisher_capital ─────────────────────────────────
        Migration(
            version="codal_publisher_capital_0002",
            description="Add version, raw_hash to codal_publisher_capital",
            up=(
                MigrationBuilder("codal_publisher_capital")
                .add_column("version", "INTEGER", nullable=False, default=1)
                .add_column("raw_hash", "TEXT", nullable=True)
                .alter_table()
            ),
            down=(
                MigrationBuilder("codal_publisher_capital")
                .drop_column("version")
                .drop_column("raw_hash")
                .alter_table()
            ),
        ),
        # ── codal_publisher_similar ─────────────────────────────────
        Migration(
            version="codal_publisher_similar_0002",
            description="Add version, raw_hash to codal_publisher_similar",
            up=(
                MigrationBuilder("codal_publisher_similar")
                .add_column("version", "INTEGER", nullable=False, default=1)
                .add_column("raw_hash", "TEXT", nullable=True)
                .alter_table()
            ),
            down=(
                MigrationBuilder("codal_publisher_similar")
                .drop_column("version")
                .drop_column("raw_hash")
                .alter_table()
            ),
        ),
        # ── codal_publisher_messages ────────────────────────────────
        Migration(
            version="codal_publisher_messages_0002",
            description="Add version, raw_hash to codal_publisher_messages",
            up=(
                MigrationBuilder("codal_publisher_messages")
                .add_column("version", "INTEGER", nullable=False, default=1)
                .add_column("raw_hash", "TEXT", nullable=True)
                .alter_table()
            ),
            down=(
                MigrationBuilder("codal_publisher_messages")
                .drop_column("version")
                .drop_column("raw_hash")
                .alter_table()
            ),
        ),
    ]