Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migration: add traffic change type #4325

Merged
merged 2 commits into from
Jul 11, 2024
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
3 changes: 2 additions & 1 deletion lib/plausible/site/spike_notification.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule Plausible.Site.SpikeNotification do

Check failure on line 1 in lib/plausible/site/spike_notification.ex

View workflow job for this annotation

GitHub Actions / App code does not change at the same time

Code and migrations shouldn't be changed at the same time
use Ecto.Schema
import Ecto.Changeset

Expand All @@ -6,6 +6,7 @@
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 @@
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
Loading