sonda/migrations/sqlite/0031_outside_plays.sql
tgiachi 3ba087bcc5 feat(import): keep the artist and the time of plays of artists I do not have
The plays of songs that are not in the library were only counted. Now, when
such a play counts as listened (not a skip, long enough), its artist and its
time are kept in a new table (migration 0031, outside_plays), so a model can
later learn which artists are played together, also those not in the library.
No title, album, IP address, country or platform is stored. The same play is
kept once however many times the export is imported, and the report says how
many were kept (history.kept_outside).
2026-11-15 10:50:29 +01:00

15 lines
983 B
SQL

-- The plays of artists a person has no music of, brought in by an import: only the name of the artist and the time,
-- enough to learn which artists are played in the same sitting (see internal/affinity). No title, album, IP address,
-- country or platform is kept. A play that is later matched to a song of the library is left out of the learning
-- (its listening event is there) and removed the next time the model is built.
CREATE TABLE outside_plays (
user_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
idempotency_key TEXT NOT NULL, -- the key of the same play as a listening event, so it is told apart from it
artist TEXT NOT NULL,
artist_key TEXT NOT NULL, -- storage.SearchKey of the name: how it meets the artists of the library
played_at INTEGER NOT NULL, -- unix seconds
PRIMARY KEY (user_id, idempotency_key)
);
CREATE INDEX idx_outside_plays_time ON outside_plays(user_id, played_at);