Files
silo-server/migrations/143_abs_playback_sessions.up.sql
T
RXWatcherandClaude Opus 4.7 db138450ac feat(audiobooks): migration 143 add abs_playback_sessions table
Tracks active /abs/api/items/{id}/play sessions for Audiobookshelf
clients so the /session/{sid}/sync and /session/{sid}/close
endpoints can record per-session listening time. Distinct from
abs_sessions (which tracks auth tokens) and user_watch_progress
(which tracks resume position).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-24 15:35:25 +02:00

25 lines
1.3 KiB
SQL

-- Active Audiobookshelf-compatible play sessions. One row per
-- /abs/api/items/{id}/play that hasn't yet been closed via
-- /abs/api/session/{sid}/close. Used to track per-session listening
-- time for ABS apps' "time listened today" stats.
CREATE TABLE IF NOT EXISTS public.abs_playback_sessions (
id TEXT PRIMARY KEY, -- ULID issued at play start
user_id INTEGER NOT NULL REFERENCES public.users(id) ON DELETE CASCADE,
profile_id TEXT NOT NULL,
content_id TEXT NOT NULL REFERENCES public.media_items(content_id) ON DELETE CASCADE,
media_file_id INTEGER REFERENCES public.media_files(id) ON DELETE SET NULL,
started_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
last_sync_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
closed_at TIMESTAMP WITH TIME ZONE,
time_listening_seconds INTEGER NOT NULL DEFAULT 0,
current_position_seconds DOUBLE PRECISION NOT NULL DEFAULT 0
);
CREATE INDEX IF NOT EXISTS idx_abs_playback_sessions_user_profile
ON public.abs_playback_sessions (user_id, profile_id);
CREATE INDEX IF NOT EXISTS idx_abs_playback_sessions_open
ON public.abs_playback_sessions (closed_at)
WHERE closed_at IS NULL;