|
| 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