Skip to content

Commit b299aa3

Browse files
authored
Migration: goal custom props + revamped unique constraints (#5940)
* Migration: add custom propos to goals + revisit unique constraints * Fixup migration
1 parent e4bc6b8 commit b299aa3

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
defmodule Plausible.Repo.Migrations.GoalsCustomProps do
2+
use Ecto.Migration
3+
4+
@disable_ddl_transaction true
5+
@disable_migration_lock true
6+
7+
# adds custom_props to goals, but also updates unique constraints to guard for either display name
8+
# or broadly speaking "goal configuration"
9+
10+
def change do
11+
drop(unique_index(:goals, [:site_id, :event_name], name: :goals_event_name_unique))
12+
13+
drop(
14+
unique_index(:goals, [:site_id, :page_path, :scroll_threshold],
15+
name: :goals_page_path_and_scroll_threshold_unique
16+
)
17+
)
18+
19+
drop(unique_index(:goals, [:site_id, :display_name], name: :goals_site_id_display_name_index))
20+
21+
alter table(:goals) do
22+
add(:custom_props, :map)
23+
end
24+
25+
create(
26+
unique_index(:goals, [:site_id, :event_name, :custom_props],
27+
where: "event_name IS NOT NULL",
28+
name: :goals_event_config_unique
29+
)
30+
)
31+
32+
create(
33+
unique_index(:goals, [:site_id, :page_path, :scroll_threshold],
34+
where: "page_path IS NOT NULL",
35+
name: :goals_pageview_config_unique
36+
)
37+
)
38+
39+
create(unique_index(:goals, [:site_id, :display_name], name: :goals_display_name_unique))
40+
end
41+
end

0 commit comments

Comments
 (0)