Skip to content

Open source, privacy-first web analytics. Lightweight, cookie-free Google Analytics alternative. Self-hosted or cloud.

Migration: include custom props in pageview goal unique index (#5978)

Adam Rutkowskib1523d3ef3e2
diff --git a/priv/repo/migrations/20260105075211_update_goals_pageview_config_unique_constraint.exs b/priv/repo/migrations/20260105075211_update_goals_pageview_config_unique_constraint.exs
new file mode 100644
index 0000000000..fccb6c924f
--- /dev/null
+++ b/priv/repo/migrations/20260105075211_update_goals_pageview_config_unique_constraint.exs
@@ -0,0 +1,22 @@
+defmodule Plausible.Repo.Migrations.UpdateGoalsPageviewConfigUniqueConstraint do
+ use Ecto.Migration
+
+ @disable_ddl_transaction true
+ @disable_migration_lock true
+
+ def change do
+ drop(
+ unique_index(:goals, [:site_id, :page_path, :scroll_threshold],
+ where: "page_path IS NOT NULL",
+ name: :goals_pageview_config_unique
+ )
+ )
+
+ create(
+ unique_index(:goals, [:site_id, :page_path, :scroll_threshold, :custom_props],
+ where: "page_path IS NOT NULL",
+ name: :goals_pageview_config_unique
+ )
+ )
+ end
+end
diff --git a/test/plausible/goals_test.exs b/test/plausible/goals_test.exs
index 3a5de96254..78ded940c7 100644
--- a/test/plausible/goals_test.exs
+++ b/test/plausible/goals_test.exs
@@ -243,6 +243,19 @@ defmodule Plausible.GoalsTest do
})
end
+ test "create/2 succeeds to create two pageview goals with different displayn names and custom props each" do
+ site = new_site()
+
+ {:ok, _} = Goals.create(site, %{"page_path" => "/index", "display_name" => "Index"})
+
+ {:ok, _} =
+ Goals.create(site, %{
+ "page_path" => "/index",
+ "display_name" => "Index 2",
+ "custom_props" => %{"foo" => "bar"}
+ })
+ end
+
test "create/2 fails to create the same currency goal twice" do
site = new_site()
{:ok, _} = Goals.create(site, %{"event_name" => "foo bar", "currency" => "EUR"})