-- What Sonda learned about which artists a person plays together (see internal/affinity), built again from the -- listening events and the plays of artists outside the library. It is only a cache of that: it can be dropped and -- built again. Artists are known by their search key, so one that is not in the library has a place too. CREATE TABLE affinity_builds ( user_id INTEGER PRIMARY KEY REFERENCES users(id) ON DELETE CASCADE, built_at INTEGER NOT NULL, -- unix seconds plays INTEGER NOT NULL, -- the plays it was built from sessions INTEGER NOT NULL, artists INTEGER NOT NULL, links INTEGER NOT NULL ); CREATE TABLE affinity_artists ( user_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE, artist_key TEXT NOT NULL, name TEXT NOT NULL, plays INTEGER NOT NULL, sessions INTEGER NOT NULL, last_played_at INTEGER NOT NULL, -- unix seconds weight REAL NOT NULL, PRIMARY KEY (user_id, artist_key) ); CREATE INDEX idx_affinity_artists_weight ON affinity_artists(user_id, weight DESC); CREATE TABLE affinity_links ( user_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE, a_key TEXT NOT NULL, -- a_key < b_key b_key TEXT NOT NULL, score REAL NOT NULL, PRIMARY KEY (user_id, a_key, b_key) ); CREATE INDEX idx_affinity_links_b ON affinity_links(user_id, b_key);