sonda/migrations/postgres/0035_favorites.sql
tgiachi 74f683d26e feat: favourites of songs, albums and artists, in the API and in apps
A person can mark songs, albums and artists as favourites. They are theirs
alone: never shown to a friend, never sent anywhere. Only what can be played is
listed.

- migration 0035 favorites, internal/favorites, storage.FavoritesRepo
- PUT/DELETE /me/favorites/{kind}/{id}, GET /me/favorites/{kind} and
  GET /me/favorites/ids, in the OpenAPI spec
- catalog.Filter IDs now also reads artists by id
- OpenSubsonic: star, unstar, getStarred2, the starred date on songs, albums and
  artists, and getAlbumList2 of type starred
2026-11-16 10:51:07 +01:00

12 lines
549 B
SQL

-- The songs, albums and artists a person marked as favourites. There is no foreign key on the item (it is in one of
-- three tables): a favourite whose item is gone is ignored when read.
CREATE TABLE favorites (
user_id BIGINT NOT NULL REFERENCES users(id) ON DELETE CASCADE,
kind TEXT NOT NULL CHECK (kind IN ('artist', 'album', 'track')),
item_id BIGINT NOT NULL,
created_at BIGINT NOT NULL,
PRIMARY KEY (user_id, kind, item_id)
);
CREATE INDEX idx_favorites_time ON favorites(user_id, kind, created_at DESC);