"""Create ``codal_publisher_similar`` table.  Revision ID: 0023

Stores similar (same-industry) publisher relationships from
``/fa/publisher/<id>/similar_publisher/``.
"""

from __future__ import annotations

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

VERSION = "0023"


def get_postgres_migrations() -> list[Migration]:
    return [
        Migration(
            version="codal_publisher_similar_0001",
            description="Create codal_publisher_similar table for same-industry publisher links",
            up=(
                MigrationBuilder("codal_publisher_similar")
                .uuid("id", primary_key=True, nullable=False)
                .bigint("publisher_id", nullable=False)
                .bigint("similar_publisher_id", nullable=False)
                .text("similar_name", nullable=True)
                .text("similar_url", nullable=True)
                .timestamp("created_at", nullable=True, default="now()")
                .timestamp("updated_at", nullable=True, default="now()")
                .index(["publisher_id"])
                .index(["similar_publisher_id"])
                .create_table()
            ),
            down=MigrationBuilder("codal_publisher_similar").drop_table(),
        ),
    ]
