diff --git a/migrations/166_trending_discover_snapshots.down.sql b/migrations/166_trending_discover_snapshots.down.sql new file mode 100644 index 00000000..72a6d6d4 --- /dev/null +++ b/migrations/166_trending_discover_snapshots.down.sql @@ -0,0 +1 @@ +DROP TABLE IF EXISTS public.trending_discover_snapshots; diff --git a/migrations/166_trending_discover_snapshots.up.sql b/migrations/166_trending_discover_snapshots.up.sql new file mode 100644 index 00000000..706d5c83 --- /dev/null +++ b/migrations/166_trending_discover_snapshots.up.sql @@ -0,0 +1,16 @@ +-- Persisted snapshot of external global trending (TMDB / Trakt) for the +-- trending_discover home section. One row per canonical (source, time_window): +-- content_ids are already resolved to library catalog content IDs and ordered +-- by trending rank. A background task refreshes these rows; the section read +-- path only reads them, so a slow or down provider never blocks the home page. +CREATE TABLE public.trending_discover_snapshots ( + source text NOT NULL, -- 'tmdb' | 'trakt' + time_window text NOT NULL, -- 'day' | 'week' (trakt pinned to 'week') + content_ids text[] NOT NULL DEFAULT '{}'::text[], + entry_count integer NOT NULL DEFAULT 0, -- raw provider entries fetched + refreshed_at timestamptz, -- last successful refresh + last_attempt_at timestamptz, -- last attempt (success or failure) + last_status text NOT NULL DEFAULT '', -- 'ok' | 'empty' | 'error' + last_error text NOT NULL DEFAULT '', + PRIMARY KEY (source, time_window) +);