"""Add request metadata columns to ``web_html_raw`` warehouse table.

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

Revision ID: 0014
"""
from __future__ import annotations

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

VERSION = "0014"


def get_doris_migrations() -> list[Migration]:
    return [
        Migration(
            version="web_html_raw_request_data_0001",
            description="Add request metadata columns to web_html_raw",
            dialect="doris",
            up=(
                MigrationBuilder("web_html_raw", dialect="doris")
                .add_column("final_url", "TEXT", nullable=True)
                .add_column("request_method", "TEXT", nullable=True)
                .add_column("redirect_chain", "JSON", nullable=True)
                .add_column("retry_count", "INT", nullable=True)
                .add_column("latency_ms", "INT", nullable=True)
                .alter_table()
            ),
            down=(
                MigrationBuilder("web_html_raw", dialect="doris")
                .drop_column("final_url")
                .drop_column("request_method")
                .drop_column("redirect_chain")
                .drop_column("retry_count")
                .drop_column("latency_ms")
                .alter_table()
            ),
        ),
    ]
