"""Add ``version`` column to ``web_media`` PostgreSQL table.

- ``version``: monotonically increasing version counter per source_url (INTEGER, default 1)

Together with ``content_hash`` this enables content-change detection
and versioned history — when content is unchanged on re-download, no
new row is inserted.

Revision ID: 0026
"""
from __future__ import annotations

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

VERSION = "0026"


def get_postgres_migrations() -> list[Migration]:
    return [
        Migration(
            version="web_media_version_0001",
            description="Add version column to web_media",
            up=(
                MigrationBuilder("web_media")
                .add_column("version", "INTEGER", nullable=True, default=1)
                .add_index(["source_url", "version"])
                .alter_table()
            ),
            down=(
                MigrationBuilder("web_media")
                .drop_column("version")
                .alter_table()
            ),
        ),
    ]
