Skip to content

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

Add unique index to shared link name

Uku Taht2fc136777c1f
diff --git a/lib/plausible/auth/api_key.ex b/lib/plausible/auth/api_key.ex
index 71fcd111bb..13c700d3ed 100644
--- a/lib/plausible/auth/api_key.ex
+++ b/lib/plausible/auth/api_key.ex
@@ -5,6 +5,7 @@ defmodule Plausible.Auth.ApiKey do
@required [:user_id, :key, :name]
schema "api_keys" do
field :name, :string
+
field :key, :string, virtual: true
field :key_hash, :string
field :key_prefix, :string
diff --git a/lib/plausible/site/shared_link.ex b/lib/plausible/site/shared_link.ex
index a63c3f59b4..e01c582f8b 100644
--- a/lib/plausible/site/shared_link.ex
+++ b/lib/plausible/site/shared_link.ex
@@ -17,6 +17,7 @@ defmodule Plausible.Site.SharedLink do
|> cast(attrs, [:slug, :password, :name])
|> validate_required([:slug, :name])
|> unique_constraint(:slug)
+ |> unique_constraint(:name, name: :shared_links_site_id_name_index)
|> hash_password()
end
diff --git a/lib/plausible_web/templates/site/edit_shared_link.html.eex b/lib/plausible_web/templates/site/edit_shared_link.html.eex
index 00b98d0b3c..e36d12fb91 100644
--- a/lib/plausible_web/templates/site/edit_shared_link.html.eex
+++ b/lib/plausible_web/templates/site/edit_shared_link.html.eex
@@ -8,5 +8,5 @@
</div>
</div>
- <%= submit "Edit shared link", class: "button mt-4 w-full" %>
+ <%= submit "Update", class: "button mt-4 w-full" %>
<% end %>
diff --git a/priv/repo/migrations/20210409074413_add_unique_index_to_shared_link_name.exs b/priv/repo/migrations/20210409074413_add_unique_index_to_shared_link_name.exs
new file mode 100644
index 0000000000..585e79de2f
--- /dev/null
+++ b/priv/repo/migrations/20210409074413_add_unique_index_to_shared_link_name.exs
@@ -0,0 +1,7 @@
+defmodule Plausible.Repo.Migrations.AddUniqueIndexToSharedLinkName do
+ use Ecto.Migration
+
+ def change do
+ create unique_index(:shared_links, [:site_id, :name], name: :shared_links_site_id_name_index)
+ end
+end