-- A rule that periodically clusters a user's recent listens by genre and -- maintains one Subsonic "mix" playlist per cluster. CREATE TABLE "cluster_mix_rule" ( id UUID NOT NULL PRIMARY KEY, tracking_user VARCHAR(250) NOT NULL, -- Listenbrainz user to cluster months INT NOT NULL DEFAULT 3, -- How many months of listens to cluster cluster_count INT, -- Number of mixes. NULL = choose automatically playlist_size INT NOT NULL DEFAULT 50, -- Tracks per mix familiar_ratio DOUBLE PRECISION NOT NULL DEFAULT 0.3, -- Share of each mix taken from recently played tracks name_template VARCHAR(250) NOT NULL DEFAULT 'Mix: {label}', -- {label} is replaced by the mix's genres refresh_hours INT NOT NULL DEFAULT 24, -- How often to rebuild the mixes last_run TIMESTAMPTZ -- When the mixes were last rebuilt ); -- The Subsonic playlists currently owned by a cluster mix rule. CREATE TABLE "cluster_mix_playlist" ( id UUID NOT NULL PRIMARY KEY, rule_id UUID NOT NULL REFERENCES "cluster_mix_rule" (id) ON DELETE CASCADE, playlist_id VARCHAR(250) NOT NULL, -- ID of the playlist in subsonic tags TEXT[] NOT NULL -- Genres describing the cluster, used to keep playlists stable across rebuilds );