"""phash_backfill_queue: kolejka scen do policzenia phasha z zapisanej miniaturki Uzasadnienie i liczby: `app/models/phash_backfill_queue.py`. Revision ID: 0028_phash_backfill_queue Revises: 0027_scenes_title_trgm Create Date: 2026-08-13 """ from __future__ import annotations import sqlalchemy as sa from alembic import op from sqlalchemy.dialects import postgresql revision: str = "0028_phash_backfill_queue" down_revision: str | None = "0027_scenes_title_trgm" branch_labels = None depends_on = None def upgrade() -> None: op.create_table( "phash_backfill_queue", sa.Column("scene_id", postgresql.UUID(as_uuid=True), nullable=False), sa.Column("thumbnail_url", sa.String(length=1024), nullable=False), sa.Column("referer", sa.String(length=255), nullable=True), sa.Column("attempts", sa.Integer(), nullable=False, server_default="0"), sa.Column("done_at", sa.DateTime(timezone=True), nullable=True), sa.Column( "created_at", sa.DateTime(timezone=True), server_default=sa.func.now(), nullable=False ), sa.ForeignKeyConstraint(["scene_id"], ["scenes.id"], ondelete="CASCADE"), sa.PrimaryKeyConstraint("scene_id"), ) # Jedyne zapytanie ścieżki gorącej: „weź N nieprzetworzonych". Indeks częściowy, # bo przetworzone wiersze zostają w tabeli jako ślad, ale nigdy ich nie czytamy. op.create_index( "ix_phash_backfill_pending", "phash_backfill_queue", ["attempts"], postgresql_where=sa.text("done_at IS NULL"), ) def downgrade() -> None: op.drop_index("ix_phash_backfill_pending", table_name="phash_backfill_queue") op.drop_table("phash_backfill_queue")