"""Add request metadata columns to ``web_media`` PostgreSQL table.

Fields: final_url, request_method, redirect_chain, retry_count,
latency_ms, status_code, response_headers.

Revision ID: 0022
"""
from __future__ import annotations

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

VERSION = "0022"


def get_postgres_migrations() -> list[Migration]:
    return [
        Migration(
            version="web_media_request_data_0001",
            description="Add request metadata columns to web_media",
            up=(
                MigrationBuilder("web_media")
                .add_column("final_url", "TEXT", nullable=True)
                .add_column("request_method", "TEXT", nullable=True)
                .add_column("redirect_chain", "JSONB", nullable=True)
                .add_column("retry_count", "INTEGER", nullable=True)
                .add_column("latency_ms", "INTEGER", nullable=True)
                .add_column("status_code", "INTEGER", nullable=True)
                .add_column("response_headers", "JSONB", nullable=True)
                .alter_table()
            ),
            down=(
                MigrationBuilder("web_media")
                .drop_column("final_url")
                .drop_column("request_method")
                .drop_column("redirect_chain")
                .drop_column("retry_count")
                .drop_column("latency_ms")
                .drop_column("status_code")
                .drop_column("response_headers")
                .alter_table()
            ),
        ),
    ]
