Skip to content

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

Migration: add traffic change type (#4325)

hq176da6b49a153
diff --git a/lib/plausible/site/spike_notification.ex b/lib/plausible/site/spike_notification.ex
index c37692da23..0c0453c32d 100644
--- a/lib/plausible/site/spike_notification.ex
+++ b/lib/plausible/site/spike_notification.ex
@@ -6,6 +6,7 @@ defmodule Plausible.Site.SpikeNotification do
field :recipients, {:array, :string}
field :threshold, :integer
field :last_sent, :naive_datetime
+ field :type, Ecto.Enum, values: [:spike, :drop], default: :spike
belongs_to :site, Plausible.Site
timestamps()
@@ -15,7 +16,7 @@ defmodule Plausible.Site.SpikeNotification do
schema
|> cast(attrs, [:site_id, :recipients, :threshold])
|> validate_required([:site_id, :recipients, :threshold])
- |> unique_constraint(:site_id)
+ |> unique_constraint([:site_id, :type])
end
def add_recipient(schema, recipient) do
diff --git a/priv/repo/migrations/20240702055817_traffic_drop_notifications.exs b/priv/repo/migrations/20240702055817_traffic_drop_notifications.exs
new file mode 100644
index 0000000000..d0ed53effb
--- /dev/null
+++ b/priv/repo/migrations/20240702055817_traffic_drop_notifications.exs
@@ -0,0 +1,13 @@
+defmodule Plausible.Repo.Migrations.TrafficDropNotifications do
+ use Ecto.Migration
+
+ def change do
+ drop index(:spike_notifications, [:site_id])
+
+ alter table(:spike_notifications) do
+ add :type, :string, default: "spike"
+ end
+
+ create unique_index(:spike_notifications, [:site_id, :type])
+ end
+end