From 54ee77995ac2a13c44afbe4d038fe6148a670442 Mon Sep 17 00:00:00 2001 From: Claudio Ortolina Date: Sat, 31 May 2025 20:24:29 +0100 Subject: [PATCH] Avoid primary key clashes --- lib/last_fm/import.ex | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/last_fm/import.ex b/lib/last_fm/import.ex index f65ab0b1..37eda8d4 100644 --- a/lib/last_fm/import.ex +++ b/lib/last_fm/import.ex @@ -17,7 +17,11 @@ defmodule LastFm.Import do |> Enum.map(fn t -> Map.take(t, @insertable_fields) end) |> Enum.map(&Map.to_list/1) - MusicLibrary.Repo.insert_all(LastFm.Track, track_params) + # HACK: if two tracks happen to have the exact same scrobbled_at_uts, + # we move it by a sec. + MusicLibrary.Repo.insert_all(LastFm.Track, track_params, + on_conflict: [inc: [scrobbled_at_uts: -1]] + ) end end end