-- name: UpsertTrackFingerprint :exec -- Written whenever a track's fingerprint is derived: by the scan when a file is -- new or its bytes changed, and by the backfill (#3908) for rows derived by an -- older method. Replaces the row wholesale — a fingerprint of the old bytes has -- no standing once the file has changed. INSERT INTO track_fingerprints ( track_id, audio_stream_sha256, chromaprint, fingerprint_version ) VALUES ( sqlc.arg(track_id), sqlc.narg(audio_stream_sha256), sqlc.narg(chromaprint), sqlc.arg(fingerprint_version) ) ON CONFLICT (track_id) DO UPDATE SET audio_stream_sha256 = EXCLUDED.audio_stream_sha256, chromaprint = EXCLUDED.chromaprint, fingerprint_version = EXCLUDED.fingerprint_version, computed_at = now(); -- name: DeleteTrackFingerprint :exec -- A file changed but could not be fingerprinted, for a reason unrelated to the -- file. The stored row describes the OLD bytes, so it goes and the backfill -- re-derives it — nothing may keep trusting a stale identity. DELETE FROM track_fingerprints WHERE track_id = $1;