"""Add parent_url to web_discovered_urls, rename source_page_url → parent_url in web_media.

Revision ID: 0016
"""
from __future__ import annotations

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

VERSION = "0016"


def get_postgres_migrations() -> list[Migration]:
    return [
        Migration(
            version="web_parent_url_0001",
            description="Add parent_url column to web_discovered_urls",
            up=(
                MigrationBuilder("web_discovered_urls")
                .add_column("parent_url", "TEXT", nullable=True)
                .alter_table()
            ),
            down=(
                MigrationBuilder("web_discovered_urls")
                .drop_column("parent_url")
                .alter_table()
            ),
        ),
        Migration(
            version="web_parent_url_0002",
            description="Rename source_page_url to parent_url in web_media",
            up=RawSqlOp(
                "ALTER TABLE web_media RENAME COLUMN source_page_url TO parent_url"
            ),
            down=RawSqlOp(
                "ALTER TABLE web_media RENAME COLUMN parent_url TO source_page_url"
            ),
        ),
    ]
