"""Create codal_publisher_pages table for publisher tab raw HTML + extracted data.

Revision ID: 0032
"""

from __future__ import annotations

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

VERSION = "0032"


def get_postgres_migrations() -> list[Migration]:
    return [
        Migration(
            version="codal_pub_pages_0001",
            description="Create codal_publisher_pages table",
            up=(
                MigrationBuilder("codal_publisher_pages")
                .uuid("id", primary_key=True, nullable=False)
                .bigint("publisher_id", nullable=False)
                .text("tab_slug", nullable=False)
                .text("tab_name", nullable=True)
                .text("tab_url", nullable=True)
                .text("raw_html", nullable=True)
                .jsonb("tab_data", nullable=True)
                .timestamp("crawl_time", nullable=True)
                .text("status", nullable=True)
                .text("error_message", nullable=True)
                .timestamp("created_at", nullable=False, default="now()")
                .timestamp("updated_at", nullable=False, default="now()")
                .index(["publisher_id", "tab_slug"], unique=True)
                .create_table()
            ),
            down=MigrationBuilder("codal_publisher_pages").drop_table(),
        ),
    ]
