diff --git a/priv/repo/migrations/20250128161815_add_scroll_threshold_to_goals.exs b/priv/repo/migrations/20250128161815_add_scroll_threshold_to_goals.exs index 935f2919e8db..3392a11d1fde 100644 --- a/priv/repo/migrations/20250128161815_add_scroll_threshold_to_goals.exs +++ b/priv/repo/migrations/20250128161815_add_scroll_threshold_to_goals.exs @@ -4,14 +4,6 @@ defmodule Plausible.Repo.Migrations.AddScrollThresholdToGoals do @disable_ddl_transaction true @disable_migration_lock true - # Plausible.Repo.Migrations.GoalsUnique - @old_index unique_index( - :goals, - [:site_id, :page_path], - where: "page_path IS NOT NULL", - name: :goals_page_path_unique - ) - @new_index unique_index( :goals, [:site_id, :page_path, :scroll_threshold], @@ -24,13 +16,11 @@ defmodule Plausible.Repo.Migrations.AddScrollThresholdToGoals do add :scroll_threshold, :smallint, null: false, default: -1 end - drop(@old_index) create(@new_index) end def down do drop(@new_index) - create(@old_index) alter table(:goals) do remove :scroll_threshold diff --git a/priv/repo/migrations/20250130121019_drop_unique_page_path_constraint_from_goals.exs b/priv/repo/migrations/20250130121019_drop_unique_page_path_constraint_from_goals.exs new file mode 100644 index 000000000000..aa4a86387fe0 --- /dev/null +++ b/priv/repo/migrations/20250130121019_drop_unique_page_path_constraint_from_goals.exs @@ -0,0 +1,22 @@ +defmodule Plausible.Repo.Migrations.DropUniquePagePathConstraintFromGoals do + use Ecto.Migration + + @disable_ddl_transaction true + @disable_migration_lock true + + # Plausible.Repo.Migrations.GoalsUnique + @old_index unique_index( + :goals, + [:site_id, :page_path], + where: "page_path IS NOT NULL", + name: :goals_page_path_unique + ) + + def up do + drop(@old_index) + end + + def down do + create(@old_index) + end +end diff --git a/test/plausible/goals_test.exs b/test/plausible/goals_test.exs index 4a519f0cd818..385cc9a46a89 100644 --- a/test/plausible/goals_test.exs +++ b/test/plausible/goals_test.exs @@ -99,8 +99,7 @@ defmodule Plausible.GoalsTest do assert {:error, changeset} = Goals.create(site, %{"page_path" => "foo bar", "display_name" => "two"}) - assert {"has already been taken", _} = - changeset.errors[:page_path] + assert {"has already been taken", _} = changeset.errors[:page_path] end test "create/2 fails to create the same custom event goal twice" do