sonda/migrations/sqlite/0020_smart_playlists.sql
tgiachi 104e41d10a feat(smart): smart playlists, playlists made of rules
A smart playlist is a set of rules, an order and a limit, kept under a name and worked out again every time it is opened.

- Rules (all that are set must hold): genres, artists and albums (is, or is not), file formats and a minimum bitrate of the same file, added in the last N days, never played, played or not played in the last N days, played at least N times, skipped or not skipped lately, only liked artists or without the avoided ones, and the length of the song.
- Orders: random (the same all day, a variant gives another), most played, least played, recently added, by title. A limit of 50 by default, 500 at most.
- GET/POST /smart-playlists, GET/PATCH/DELETE /smart-playlists/{id}, GET /smart-playlists/{id}/tracks, POST /smart-playlists/preview to try rules without keeping them, and POST /smart-playlists/{id}/playlist to keep what is shown as a normal playlist.
- Only the rules are stored (migration 0020); the songs come from the files and from the owner's own history and taste. Nothing is sent to a provider, and a smart playlist is its owner's alone. A user can have 200.
- Mixes and smart playlists share the way a list of songs becomes a playlist.
2026-11-13 09:36:52 +01:00

17 lines
723 B
SQL

-- Smart playlists: playlists that are a set of rules, worked out again every time they are opened.
-- Only the rules are kept (as JSON, read and written by the code, never searched), with the order
-- and the most songs they give.
CREATE TABLE smart_playlists (
id INTEGER PRIMARY KEY,
user_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
name TEXT NOT NULL,
description TEXT NOT NULL DEFAULT '',
rules TEXT NOT NULL,
sort TEXT NOT NULL,
max_tracks INTEGER NOT NULL,
created_at INTEGER NOT NULL, -- unix seconds
updated_at INTEGER NOT NULL
);
CREATE INDEX idx_smart_playlists_user ON smart_playlists(user_id, updated_at);