Store release ids when importing a record
This commit is contained in:
@@ -19,6 +19,7 @@ defmodule MusicLibrary.Records.Record do
|
|||||||
field :genres, {:array, :string}
|
field :genres, {:array, :string}
|
||||||
field :release, :string
|
field :release, :string
|
||||||
field :purchased_at, :utc_datetime
|
field :purchased_at, :utc_datetime
|
||||||
|
field :release_ids, {:array, :string}
|
||||||
|
|
||||||
embeds_many :artists, Artist do
|
embeds_many :artists, Artist do
|
||||||
field :name, :string
|
field :name, :string
|
||||||
@@ -41,6 +42,7 @@ defmodule MusicLibrary.Records.Record do
|
|||||||
:musicbrainz_data,
|
:musicbrainz_data,
|
||||||
:release,
|
:release,
|
||||||
:genres,
|
:genres,
|
||||||
|
:release_ids,
|
||||||
:cover_url,
|
:cover_url,
|
||||||
:cover_data,
|
:cover_data,
|
||||||
:purchased_at
|
:purchased_at
|
||||||
@@ -117,6 +119,7 @@ defmodule MusicLibrary.Records.Record do
|
|||||||
"release" => release_group["first-release-date"],
|
"release" => release_group["first-release-date"],
|
||||||
"type" => parse_subtype(release_group["primary-type"]),
|
"type" => parse_subtype(release_group["primary-type"]),
|
||||||
"genres" => Enum.map(release_group["genres"], fn g -> g["name"] end),
|
"genres" => Enum.map(release_group["genres"], fn g -> g["name"] end),
|
||||||
|
"release_ids" => Enum.map(release_group["releases"], fn r -> r["id"] end),
|
||||||
"cover_url" => "https://coverartarchive.org/release-group/#{musicbrainz_id}/front"
|
"cover_url" => "https://coverartarchive.org/release-group/#{musicbrainz_id}/front"
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
defmodule MusicLibrary.Repo.Migrations.AddReleaseIdsToRecords do
|
||||||
|
use Ecto.Migration
|
||||||
|
|
||||||
|
def change do
|
||||||
|
alter table(:records) do
|
||||||
|
add :release_ids, {:array, :string}, default: []
|
||||||
|
end
|
||||||
|
|
||||||
|
create index(:records, [:release_ids])
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -165,6 +165,19 @@ defmodule MusicLibrary.RecordsTest do
|
|||||||
assert record.title == "Marbles"
|
assert record.title == "Marbles"
|
||||||
assert record.format == :vinyl
|
assert record.format == :vinyl
|
||||||
assert record.purchased_at == DateTime.truncate(current_time, :second)
|
assert record.purchased_at == DateTime.truncate(current_time, :second)
|
||||||
|
|
||||||
|
assert record.release_ids ==
|
||||||
|
[
|
||||||
|
"0e290154-5375-4f4f-a658-4a92bf02faa5",
|
||||||
|
"3f1cc80f-4507-48a9-899c-c1bda83280c2",
|
||||||
|
"d3f9b9e2-73f5-4b47-a2a7-2c2199aad608",
|
||||||
|
"2c4ecd84-7a84-4f42-a600-2f00ed8978c9",
|
||||||
|
"ab151aa6-7538-4e93-be60-eded52b5b7b7",
|
||||||
|
"b94bbd1f-ae5d-4e7b-98ff-28bfe135f20c",
|
||||||
|
"4b9fe13b-4837-4c02-9368-e97ba6f5a086",
|
||||||
|
"a4b02377-0b5e-448e-9cd6-5500c0378523",
|
||||||
|
"f3937bc5-b99f-443a-9609-a404201f21ca"
|
||||||
|
]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -205,6 +218,19 @@ defmodule MusicLibrary.RecordsTest do
|
|||||||
assert record.title == "Marbles"
|
assert record.title == "Marbles"
|
||||||
assert record.format == :vinyl
|
assert record.format == :vinyl
|
||||||
assert record.purchased_at == DateTime.truncate(current_time, :second)
|
assert record.purchased_at == DateTime.truncate(current_time, :second)
|
||||||
|
|
||||||
|
assert record.release_ids ==
|
||||||
|
[
|
||||||
|
"0e290154-5375-4f4f-a658-4a92bf02faa5",
|
||||||
|
"3f1cc80f-4507-48a9-899c-c1bda83280c2",
|
||||||
|
"d3f9b9e2-73f5-4b47-a2a7-2c2199aad608",
|
||||||
|
"2c4ecd84-7a84-4f42-a600-2f00ed8978c9",
|
||||||
|
"ab151aa6-7538-4e93-be60-eded52b5b7b7",
|
||||||
|
"b94bbd1f-ae5d-4e7b-98ff-28bfe135f20c",
|
||||||
|
"4b9fe13b-4837-4c02-9368-e97ba6f5a086",
|
||||||
|
"a4b02377-0b5e-448e-9cd6-5500c0378523",
|
||||||
|
"f3937bc5-b99f-443a-9609-a404201f21ca"
|
||||||
|
]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -95,6 +95,269 @@ defmodule MusicLibrary.ReleaseGroupsFixtures do
|
|||||||
"id" => "20790e26-98e4-3ad3-a67f-b674758b942d",
|
"id" => "20790e26-98e4-3ad3-a67f-b674758b942d",
|
||||||
"primary-type" => "Album",
|
"primary-type" => "Album",
|
||||||
"primary-type-id" => "f529b476-6e62-324f-b0aa-1f3e33d313fc",
|
"primary-type-id" => "f529b476-6e62-324f-b0aa-1f3e33d313fc",
|
||||||
|
"releases" => [
|
||||||
|
%{
|
||||||
|
"barcode" => "",
|
||||||
|
"country" => "XE",
|
||||||
|
"date" => "2004-05-03",
|
||||||
|
"disambiguation" => "non‐deluxe double CD with o‐card",
|
||||||
|
"genres" => [],
|
||||||
|
"id" => "0e290154-5375-4f4f-a658-4a92bf02faa5",
|
||||||
|
"packaging" => "Jewel Case",
|
||||||
|
"packaging-id" => "ec27701a-4a22-37f4-bfac-6616e0f9750a",
|
||||||
|
"quality" => "normal",
|
||||||
|
"release-events" => [
|
||||||
|
%{
|
||||||
|
"area" => %{
|
||||||
|
"disambiguation" => "",
|
||||||
|
"id" => "89a675c2-3e37-3518-b83c-418bad59a85a",
|
||||||
|
"iso-3166-1-codes" => ["XE"],
|
||||||
|
"name" => "Europe",
|
||||||
|
"sort-name" => "Europe",
|
||||||
|
"type" => nil,
|
||||||
|
"type-id" => nil
|
||||||
|
},
|
||||||
|
"date" => "2004-05-03"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"status" => "Official",
|
||||||
|
"status-id" => "4e304316-386d-3409-af2e-78857eec5cfe",
|
||||||
|
"text-representation" => %{"language" => "eng", "script" => "Latn"},
|
||||||
|
"title" => "Marbles"
|
||||||
|
},
|
||||||
|
%{
|
||||||
|
"barcode" => "",
|
||||||
|
"country" => "GB",
|
||||||
|
"date" => "2004-05-03",
|
||||||
|
"disambiguation" => "limited deluxe campaign edition",
|
||||||
|
"genres" => [],
|
||||||
|
"id" => "3f1cc80f-4507-48a9-899c-c1bda83280c2",
|
||||||
|
"packaging" => "Other",
|
||||||
|
"packaging-id" => "815b7785-8284-3926-8f04-e48bc6c4d102",
|
||||||
|
"quality" => "normal",
|
||||||
|
"release-events" => [
|
||||||
|
%{
|
||||||
|
"area" => %{
|
||||||
|
"disambiguation" => "",
|
||||||
|
"id" => "8a754a16-0027-3a29-b6d7-2b40ea0481ed",
|
||||||
|
"iso-3166-1-codes" => ["GB"],
|
||||||
|
"name" => "United Kingdom",
|
||||||
|
"sort-name" => "United Kingdom",
|
||||||
|
"type" => nil,
|
||||||
|
"type-id" => nil
|
||||||
|
},
|
||||||
|
"date" => "2004-05-03"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"status" => "Official",
|
||||||
|
"status-id" => "4e304316-386d-3409-af2e-78857eec5cfe",
|
||||||
|
"text-representation" => %{"language" => "eng", "script" => "Latn"},
|
||||||
|
"title" => "Marbles"
|
||||||
|
},
|
||||||
|
%{
|
||||||
|
"barcode" => "5037300650128",
|
||||||
|
"country" => "GB",
|
||||||
|
"date" => "2004-05-03",
|
||||||
|
"disambiguation" => "",
|
||||||
|
"genres" => [],
|
||||||
|
"id" => "d3f9b9e2-73f5-4b47-a2a7-2c2199aad608",
|
||||||
|
"packaging" => "Jewel Case",
|
||||||
|
"packaging-id" => "ec27701a-4a22-37f4-bfac-6616e0f9750a",
|
||||||
|
"quality" => "normal",
|
||||||
|
"release-events" => [
|
||||||
|
%{
|
||||||
|
"area" => %{
|
||||||
|
"disambiguation" => "",
|
||||||
|
"id" => "8a754a16-0027-3a29-b6d7-2b40ea0481ed",
|
||||||
|
"iso-3166-1-codes" => ["GB"],
|
||||||
|
"name" => "United Kingdom",
|
||||||
|
"sort-name" => "United Kingdom",
|
||||||
|
"type" => nil,
|
||||||
|
"type-id" => nil
|
||||||
|
},
|
||||||
|
"date" => "2004-05-03"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"status" => "Official",
|
||||||
|
"status-id" => "4e304316-386d-3409-af2e-78857eec5cfe",
|
||||||
|
"text-representation" => %{"language" => "eng", "script" => "Latn"},
|
||||||
|
"title" => "Marbles"
|
||||||
|
},
|
||||||
|
%{
|
||||||
|
"barcode" => "",
|
||||||
|
"country" => "RU",
|
||||||
|
"date" => "2004",
|
||||||
|
"disambiguation" => "",
|
||||||
|
"genres" => [],
|
||||||
|
"id" => "2c4ecd84-7a84-4f42-a600-2f00ed8978c9",
|
||||||
|
"packaging" => "Jewel Case",
|
||||||
|
"packaging-id" => "ec27701a-4a22-37f4-bfac-6616e0f9750a",
|
||||||
|
"quality" => "normal",
|
||||||
|
"release-events" => [
|
||||||
|
%{
|
||||||
|
"area" => %{
|
||||||
|
"disambiguation" => "",
|
||||||
|
"id" => "1f1fc3a4-9500-39b8-9f10-f0a465557eef",
|
||||||
|
"iso-3166-1-codes" => ["RU"],
|
||||||
|
"name" => "Russia",
|
||||||
|
"sort-name" => "Russia",
|
||||||
|
"type" => nil,
|
||||||
|
"type-id" => nil
|
||||||
|
},
|
||||||
|
"date" => "2004"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"status" => "Bootleg",
|
||||||
|
"status-id" => "1156806e-d06a-38bd-83f0-cf2284a808b9",
|
||||||
|
"text-representation" => %{"language" => "eng", "script" => "Latn"},
|
||||||
|
"title" => "Marbles"
|
||||||
|
},
|
||||||
|
%{
|
||||||
|
"barcode" => "803341127920",
|
||||||
|
"country" => "US",
|
||||||
|
"date" => "2004",
|
||||||
|
"disambiguation" => "",
|
||||||
|
"genres" => [],
|
||||||
|
"id" => "ab151aa6-7538-4e93-be60-eded52b5b7b7",
|
||||||
|
"packaging" => nil,
|
||||||
|
"packaging-id" => nil,
|
||||||
|
"quality" => "normal",
|
||||||
|
"release-events" => [
|
||||||
|
%{
|
||||||
|
"area" => %{
|
||||||
|
"disambiguation" => "",
|
||||||
|
"id" => "489ce91b-6658-3307-9877-795b68554c98",
|
||||||
|
"iso-3166-1-codes" => ["US"],
|
||||||
|
"name" => "United States",
|
||||||
|
"sort-name" => "United States",
|
||||||
|
"type" => nil,
|
||||||
|
"type-id" => nil
|
||||||
|
},
|
||||||
|
"date" => "2004"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"status" => "Official",
|
||||||
|
"status-id" => "4e304316-386d-3409-af2e-78857eec5cfe",
|
||||||
|
"text-representation" => %{"language" => "eng", "script" => "Latn"},
|
||||||
|
"title" => "Marbles"
|
||||||
|
},
|
||||||
|
%{
|
||||||
|
"barcode" => "636551597210",
|
||||||
|
"country" => "GB",
|
||||||
|
"date" => "2011-04-25",
|
||||||
|
"disambiguation" => "",
|
||||||
|
"genres" => [],
|
||||||
|
"id" => "b94bbd1f-ae5d-4e7b-98ff-28bfe135f20c",
|
||||||
|
"packaging" => "Cardboard/Paper Sleeve",
|
||||||
|
"packaging-id" => "f7101ce3-0384-39ce-9fde-fbbd0044d35f",
|
||||||
|
"quality" => "normal",
|
||||||
|
"release-events" => [
|
||||||
|
%{
|
||||||
|
"area" => %{
|
||||||
|
"disambiguation" => "",
|
||||||
|
"id" => "8a754a16-0027-3a29-b6d7-2b40ea0481ed",
|
||||||
|
"iso-3166-1-codes" => ["GB"],
|
||||||
|
"name" => "United Kingdom",
|
||||||
|
"sort-name" => "United Kingdom",
|
||||||
|
"type" => nil,
|
||||||
|
"type-id" => nil
|
||||||
|
},
|
||||||
|
"date" => "2011-04-25"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"status" => "Official",
|
||||||
|
"status-id" => "4e304316-386d-3409-af2e-78857eec5cfe",
|
||||||
|
"text-representation" => %{"language" => "eng", "script" => "Latn"},
|
||||||
|
"title" => "Marbles"
|
||||||
|
},
|
||||||
|
%{
|
||||||
|
"barcode" => "636551597227",
|
||||||
|
"country" => "GB",
|
||||||
|
"date" => "2011-04-25",
|
||||||
|
"disambiguation" => "",
|
||||||
|
"genres" => [],
|
||||||
|
"id" => "4b9fe13b-4837-4c02-9368-e97ba6f5a086",
|
||||||
|
"packaging" => "Digibook",
|
||||||
|
"packaging-id" => "9f2e13bc-f84f-428a-8342-fd86ece7fc4d",
|
||||||
|
"quality" => "normal",
|
||||||
|
"release-events" => [
|
||||||
|
%{
|
||||||
|
"area" => %{
|
||||||
|
"disambiguation" => "",
|
||||||
|
"id" => "8a754a16-0027-3a29-b6d7-2b40ea0481ed",
|
||||||
|
"iso-3166-1-codes" => ["GB"],
|
||||||
|
"name" => "United Kingdom",
|
||||||
|
"sort-name" => "United Kingdom",
|
||||||
|
"type" => nil,
|
||||||
|
"type-id" => nil
|
||||||
|
},
|
||||||
|
"date" => "2011-04-25"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"status" => "Official",
|
||||||
|
"status-id" => "4e304316-386d-3409-af2e-78857eec5cfe",
|
||||||
|
"text-representation" => %{"language" => "eng", "script" => "Latn"},
|
||||||
|
"title" => "Marbles"
|
||||||
|
},
|
||||||
|
%{
|
||||||
|
"barcode" => "636551808613",
|
||||||
|
"country" => "XE",
|
||||||
|
"date" => "2017",
|
||||||
|
"disambiguation" => "",
|
||||||
|
"genres" => [],
|
||||||
|
"id" => "a4b02377-0b5e-448e-9cd6-5500c0378523",
|
||||||
|
"packaging" => "Other",
|
||||||
|
"packaging-id" => "815b7785-8284-3926-8f04-e48bc6c4d102",
|
||||||
|
"quality" => "normal",
|
||||||
|
"release-events" => [
|
||||||
|
%{
|
||||||
|
"area" => %{
|
||||||
|
"disambiguation" => "",
|
||||||
|
"id" => "89a675c2-3e37-3518-b83c-418bad59a85a",
|
||||||
|
"iso-3166-1-codes" => ["XE"],
|
||||||
|
"name" => "Europe",
|
||||||
|
"sort-name" => "Europe",
|
||||||
|
"type" => nil,
|
||||||
|
"type-id" => nil
|
||||||
|
},
|
||||||
|
"date" => "2017"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"status" => "Official",
|
||||||
|
"status-id" => "4e304316-386d-3409-af2e-78857eec5cfe",
|
||||||
|
"text-representation" => %{"language" => "eng", "script" => "Latn"},
|
||||||
|
"title" => "Marbles"
|
||||||
|
},
|
||||||
|
%{
|
||||||
|
"barcode" => "859724565117",
|
||||||
|
"country" => "XW",
|
||||||
|
"date" => "",
|
||||||
|
"disambiguation" => "",
|
||||||
|
"genres" => [],
|
||||||
|
"id" => "f3937bc5-b99f-443a-9609-a404201f21ca",
|
||||||
|
"packaging" => "None",
|
||||||
|
"packaging-id" => "119eba76-b343-3e02-a292-f0f00644bb9b",
|
||||||
|
"quality" => "normal",
|
||||||
|
"release-events" => [
|
||||||
|
%{
|
||||||
|
"area" => %{
|
||||||
|
"disambiguation" => "",
|
||||||
|
"id" => "525d4e18-3d00-31b9-a58b-a146a916de8f",
|
||||||
|
"iso-3166-1-codes" => ["XW"],
|
||||||
|
"name" => "[Worldwide]",
|
||||||
|
"sort-name" => "[Worldwide]",
|
||||||
|
"type" => nil,
|
||||||
|
"type-id" => nil
|
||||||
|
},
|
||||||
|
"date" => ""
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"status" => "Official",
|
||||||
|
"status-id" => "4e304316-386d-3409-af2e-78857eec5cfe",
|
||||||
|
"text-representation" => %{"language" => "eng", "script" => "Latn"},
|
||||||
|
"title" => "Marbles"
|
||||||
|
}
|
||||||
|
],
|
||||||
"secondary-type-ids" => [],
|
"secondary-type-ids" => [],
|
||||||
"secondary-types" => [],
|
"secondary-types" => [],
|
||||||
"title" => "Marbles"
|
"title" => "Marbles"
|
||||||
|
|||||||
Reference in New Issue
Block a user