Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/plausible/goal/schema.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ defmodule Plausible.Goal do
schema "goals" do
field :event_name, :string
field :page_path, :string
field :scroll_threshold, :integer, default: -1
field :display_name, :string

on_ee do
Expand All @@ -23,7 +24,7 @@ defmodule Plausible.Goal do
timestamps()
end

@fields [:id, :site_id, :event_name, :page_path, :display_name] ++
@fields [:id, :site_id, :event_name, :page_path, :scroll_threshold, :display_name] ++
on_ee(do: [:currency], else: [])

@max_event_name_length 120
Expand All @@ -40,6 +41,9 @@ defmodule Plausible.Goal do
|> maybe_put_display_name()
|> unique_constraint(:event_name, name: :goals_event_name_unique)
|> unique_constraint(:page_path, name: :goals_page_path_unique)
|> unique_constraint([:page_path, :scroll_threshold],
name: :goals_page_path_and_scroll_threshold_unique
)
|> unique_constraint(:display_name, name: :goals_site_id_display_name_index)
|> validate_length(:event_name, max: @max_event_name_length)
|> check_constraint(:event_name,
Expand Down
7 changes: 5 additions & 2 deletions test/plausible/goals_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,11 @@ defmodule Plausible.GoalsTest do

test "create/2 fails to create the same pageview goal twice" do
site = new_site()
{:ok, _} = Goals.create(site, %{"page_path" => "foo bar"})
assert {:error, changeset} = Goals.create(site, %{"page_path" => "foo bar"})
{:ok, _} = Goals.create(site, %{"page_path" => "foo bar", "display_name" => "one"})

assert {:error, changeset} =
Goals.create(site, %{"page_path" => "foo bar", "display_name" => "two"})

assert {"has already been taken", _} = changeset.errors[:page_path]
end

Expand Down
Loading