Add batch function to remove artist IDs

This commit is contained in:
Claudio Ortolina
2024-12-02 09:37:00 +00:00
parent 228b4bc440
commit 3733ef74ba
+7
View File
@@ -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)