From 38998bfe0f45b2c38e4d8cc29014249329b1bba0 Mon Sep 17 00:00:00 2001 From: Kieran Eglin Date: Wed, 20 Mar 2024 11:16:11 -0700 Subject: [PATCH] Removed unique index across a source's collection and its media profile --- lib/pinchflat/sources/source.ex | 1 - ...81210_remove_unique_index_from_sources.exs | 7 +++ test/pinchflat/sources_test.exs | 43 ------------------- 3 files changed, 7 insertions(+), 44 deletions(-) create mode 100644 priv/repo/migrations/20240320181210_remove_unique_index_from_sources.exs diff --git a/lib/pinchflat/sources/source.ex b/lib/pinchflat/sources/source.ex index 266ac85..1de247c 100644 --- a/lib/pinchflat/sources/source.ex +++ b/lib/pinchflat/sources/source.ex @@ -98,7 +98,6 @@ defmodule Pinchflat.Sources.Source do |> dynamic_default(:custom_name, fn cs -> get_field(cs, :collection_name) end) |> validate_required(required_fields) |> cast_assoc(:metadata, with: &SourceMetadata.changeset/2, required: false) - |> unique_constraint([:collection_id, :media_profile_id]) end @doc false diff --git a/priv/repo/migrations/20240320181210_remove_unique_index_from_sources.exs b/priv/repo/migrations/20240320181210_remove_unique_index_from_sources.exs new file mode 100644 index 0000000..c77faf2 --- /dev/null +++ b/priv/repo/migrations/20240320181210_remove_unique_index_from_sources.exs @@ -0,0 +1,7 @@ +defmodule Pinchflat.Repo.Migrations.RemoveUniqueIndexFromSources do + use Ecto.Migration + + def change do + drop unique_index(:sources, [:collection_id, :media_profile_id]) + end +end diff --git a/test/pinchflat/sources_test.exs b/test/pinchflat/sources_test.exs index 7dcbe07..ce247a2 100644 --- a/test/pinchflat/sources_test.exs +++ b/test/pinchflat/sources_test.exs @@ -138,49 +138,6 @@ defmodule Pinchflat.SourcesTest do assert {:error, %Ecto.Changeset{}} = Sources.create_source(@invalid_source_attrs) end - test "creation enforces uniqueness of collection_id scoped to the media_profile" do - expect(YtDlpRunnerMock, :run, 2, fn _url, _opts, _ot -> - {:ok, - Phoenix.json_library().encode!(%{ - channel: "some channel name", - channel_id: "some_channel_id_12345678", - playlist_id: "some_channel_id_12345678", - playlist_title: "some channel name - videos" - })} - end) - - valid_once_attrs = %{ - media_profile_id: media_profile_fixture().id, - original_url: "https://www.youtube.com/channel/abc123" - } - - assert {:ok, %Source{}} = Sources.create_source(valid_once_attrs) - assert {:error, %Ecto.Changeset{}} = Sources.create_source(valid_once_attrs) - end - - test "creation lets you duplicate collection_ids as long as the media profile is different" do - expect(YtDlpRunnerMock, :run, 2, fn _url, _opts, _ot -> - {:ok, - Phoenix.json_library().encode!(%{ - channel: "some channel name", - channel_id: "some_channel_id_12345678", - playlist_id: "some_channel_id_12345678", - playlist_title: "some channel name - videos" - })} - end) - - valid_attrs = %{ - name: "some name", - original_url: "https://www.youtube.com/channel/abc123" - } - - source_1_attrs = Map.merge(valid_attrs, %{media_profile_id: media_profile_fixture().id}) - source_2_attrs = Map.merge(valid_attrs, %{media_profile_id: media_profile_fixture().id}) - - assert {:ok, %Source{}} = Sources.create_source(source_1_attrs) - assert {:ok, %Source{}} = Sources.create_source(source_2_attrs) - end - test "creation will schedule the indexing task" do expect(YtDlpRunnerMock, :run, &channel_mock/3)