From 3733ef74baad7d9efefe9349ff45899f18df31c5 Mon Sep 17 00:00:00 2001 From: Claudio Ortolina Date: Mon, 2 Dec 2024 09:37:00 +0000 Subject: [PATCH] Add batch function to remove artist IDs --- lib/music_library/records/batch.ex | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/music_library/records/batch.ex b/lib/music_library/records/batch.ex index 4bc5e8f6..de58ecd7 100644 --- a/lib/music_library/records/batch.ex +++ b/lib/music_library/records/batch.ex @@ -52,6 +52,13 @@ defmodule MusicLibrary.Records.Batch do |> Repo.update() end + def remove_artists_ids! do + # Shotgun approach: remove the first 4 artists IDs from each record. + # This is not a general solution, but it works as a quick fix because the record with the most artists has 3. + q = "update records set artists = json_remove(artists, '$[0].id', '$[1].id', '$[2].id', '$[3].id');" + Repo.query(q) + end + defp run_on_all_records(fun) do q = from(r in Record) stream = Repo.stream(q, max_rows: 50)