"""Create codal_request_logs table for request auditing.

Revision ID: 0033
"""

from __future__ import annotations

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

VERSION = "0033"


def get_postgres_migrations() -> list[Migration]:
    return [
        Migration(
            version="codal_reqlog_0001",
            description="Create codal_request_logs table",
            up=(
                MigrationBuilder("codal_request_logs")
                .uuid("id", primary_key=True, nullable=False)
                .text("url", nullable=False)
                .timestamp("request_at", nullable=True)
                .text("raw_html", nullable=True)
                .text("sha256", nullable=True)
                .integer("status_code", nullable=True)
                .integer("duration_ms", nullable=True)
                .timestamp("created_at", nullable=False, default="now()")
                .timestamp("updated_at", nullable=False, default="now()")
                .index(["url"])
                .index(["request_at"])
                .create_table()
            ),
            down=MigrationBuilder("codal_request_logs").drop_table(),
        ),
    ]
