arnaucube
arnaucube/jellyfin-toolsPublic Self-hosted repository
jellyfin-tools/jellyfin-year-review/scripts/jellystat-export.sql
jellyfin-year-review/scripts/jellystat-export.sqlRaw
 1-- Run with psql -XqAt -v ON_ERROR_STOP=1 -f scripts/jellystat-export.sql
 2-- The role needs SELECT only; the transaction takes one consistent PostgreSQL snapshot.
 3BEGIN ISOLATION LEVEL REPEATABLE READ READ ONLY;
 4SELECT json_build_object(
 5  'Id', "Id", 'UserId', "UserId", 'NowPlayingItemId', "NowPlayingItemId",
 6  'EpisodeId', "EpisodeId", 'PlaybackDuration', "PlaybackDuration",
 7  'ActivityDateInserted', to_char("ActivityDateInserted" AT TIME ZONE 'UTC', 'YYYY-MM-DD"T"HH24:MI:SS.MS"Z"'),
 8  'DeviceName', "DeviceName", 'Client', "Client", 'Imported', false
 9)::text
10FROM public.jf_playback_activity
11WHERE COALESCE(imported, false) = false
12ORDER BY "Id";
13COMMIT;