"""Add fair-priority tracking to web_discovered_urls.

Revision ID: 0026
"""
from __future__ import annotations

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

VERSION = "0026"


def get_postgres_migrations() -> list[Migration]:
    return [
        Migration(
            version="web_url_fair_priority_0001",
            description="Add attempt_number and fair_priority columns to web_discovered_urls",
            up=RawSqlOp(
                [
                    "ALTER TABLE web_discovered_urls ADD COLUMN attempt_number INTEGER NOT NULL DEFAULT 0",
                    "ALTER TABLE web_discovered_urls ADD COLUMN fair_priority INTEGER NOT NULL DEFAULT 100",
                    "UPDATE web_discovered_urls SET fair_priority = priority, attempt_number = 0",
                ]
            ),
            down=RawSqlOp(
                [
                    "ALTER TABLE web_discovered_urls DROP COLUMN fair_priority",
                    "ALTER TABLE web_discovered_urls DROP COLUMN attempt_number",
                ]
            ),
        ),
    ]