Skip to content

Commit

Permalink
Migration: add traffic change type (#4325)
Browse files Browse the repository at this point in the history
* Migration: add traffic change type

* Update schema
  • Loading branch information
aerosol authored Jul 11, 2024
1 parent 0114689 commit 76da6b4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/plausible/site/spike_notification.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
Expand Down
13 changes: 13 additions & 0 deletions priv/repo/migrations/20240702055817_traffic_drop_notifications.exs
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 76da6b4

Please sign in to comment.