Skip to content

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

Page Scroll Goals: migration step 1 (#5033)

RobertJoonase059468265dd
diff --git a/priv/repo/migrations/20250128161815_add_scroll_threshold_to_goals.exs b/priv/repo/migrations/20250128161815_add_scroll_threshold_to_goals.exs
new file mode 100644
index 0000000000..3392a11d1f
--- /dev/null
+++ b/priv/repo/migrations/20250128161815_add_scroll_threshold_to_goals.exs
@@ -0,0 +1,29 @@
+defmodule Plausible.Repo.Migrations.AddScrollThresholdToGoals do
+ use Ecto.Migration
+
+ @disable_ddl_transaction true
+ @disable_migration_lock true
+
+ @new_index unique_index(
+ :goals,
+ [:site_id, :page_path, :scroll_threshold],
+ where: "page_path IS NOT NULL",
+ name: :goals_page_path_and_scroll_threshold_unique
+ )
+
+ def up do
+ alter table(:goals) do
+ add :scroll_threshold, :smallint, null: false, default: -1
+ end
+
+ create(@new_index)
+ end
+
+ def down do
+ drop(@new_index)
+
+ alter table(:goals) do
+ remove :scroll_threshold
+ end
+ end
+end