Backend (migration 0047_plex_collections): a plex_collections table mirrors every Plex collection (card metadata + smart flag + an editable flag reserved for Phase 2); membership is stored as GIN-indexed collection_keys on member movies (plex_items) and shows (plex_shows). The background sync (plex_sync) now fetches each library's collections + their children and rebuilds membership — so ALL reads are local (Plex's dual-language collection queries are slow; this trades a ~4-min background sync for instant reads). New /api/plex/collections endpoint; /browse gains a combinable filter; item_detail returns the movie's collection 'strips' (sibling titles as playable cards, smallest/most-specific collection first) — all pure local lookups. Frontend: PlexSidebar gains a searchable Collection picker + an active-collection chip; PlexInfo renders the collection strips (playable posters + 'Browse collection' → sets the filter); the collection is part of PlexFilters (persisted). i18n en/hu/de. Phase 2 (create/edit collections with write-back to Plex) is separate.
57 lines
3 KiB
Python
57 lines
3 KiB
Python
"""Plex collections
|
|
|
|
Revision ID: 0047_plex_collections
|
|
Revises: 0046_plex_people_search
|
|
Create Date: 2026-07-06
|
|
|
|
Mirrors Plex collections locally so reads never hit Plex's slow (dual-language) collection queries.
|
|
A `plex_collections` table holds each collection's card metadata; membership is stored as GIN-indexed
|
|
`collection_keys` on the member movies (plex_items) and shows (plex_shows), so a collection can be a
|
|
combinable filter and a title's "collection strip" is a pure local lookup. `editable` marks the
|
|
(curated) collections we may later write back to Plex; everything is read-only by default.
|
|
"""
|
|
from typing import Sequence, Union
|
|
|
|
import sqlalchemy as sa
|
|
from alembic import op
|
|
from sqlalchemy.dialects import postgresql
|
|
|
|
revision: str = "0047_plex_collections"
|
|
down_revision: Union[str, None] = "0046_plex_people_search"
|
|
branch_labels: Union[str, Sequence[str], None] = None
|
|
depends_on: Union[str, Sequence[str], None] = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
op.create_table(
|
|
"plex_collections",
|
|
sa.Column("id", sa.Integer(), primary_key=True),
|
|
sa.Column("rating_key", sa.String(length=32), nullable=False),
|
|
sa.Column("library_id", sa.Integer(), sa.ForeignKey("plex_libraries.id", ondelete="CASCADE"), nullable=False),
|
|
sa.Column("title", sa.String(length=512), nullable=False),
|
|
sa.Column("summary", sa.Text(), nullable=True),
|
|
sa.Column("thumb_key", sa.String(length=512), nullable=True),
|
|
sa.Column("child_count", sa.Integer(), nullable=True),
|
|
sa.Column("smart", sa.Boolean(), nullable=False, server_default="false"),
|
|
sa.Column("editable", sa.Boolean(), nullable=False, server_default="false"),
|
|
sa.Column("synced_at", sa.DateTime(timezone=True), nullable=True),
|
|
sa.Column("created_at", sa.DateTime(timezone=True), server_default=sa.text("now()"), nullable=False),
|
|
sa.Column("updated_at", sa.DateTime(timezone=True), server_default=sa.text("now()"), nullable=False),
|
|
)
|
|
op.create_index("ix_plex_collections_rating_key", "plex_collections", ["rating_key"], unique=True)
|
|
op.create_index("ix_plex_collections_library_id", "plex_collections", ["library_id"])
|
|
|
|
op.add_column("plex_items", sa.Column("collection_keys", postgresql.JSONB(), nullable=True))
|
|
op.create_index("ix_plex_items_collections_gin", "plex_items", ["collection_keys"], postgresql_using="gin")
|
|
op.add_column("plex_shows", sa.Column("collection_keys", postgresql.JSONB(), nullable=True))
|
|
op.create_index("ix_plex_shows_collections_gin", "plex_shows", ["collection_keys"], postgresql_using="gin")
|
|
|
|
|
|
def downgrade() -> None:
|
|
op.drop_index("ix_plex_shows_collections_gin", table_name="plex_shows")
|
|
op.drop_column("plex_shows", "collection_keys")
|
|
op.drop_index("ix_plex_items_collections_gin", table_name="plex_items")
|
|
op.drop_column("plex_items", "collection_keys")
|
|
op.drop_index("ix_plex_collections_library_id", table_name="plex_collections")
|
|
op.drop_index("ix_plex_collections_rating_key", table_name="plex_collections")
|
|
op.drop_table("plex_collections")
|