Skip to content

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

Cascade delete sent_renewal_notifications table when user is deleted (#2549)

Vini Brasilb6d30019efe3
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 528a10bded..6f16806691 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,9 @@ All notable changes to this project will be documented in this file.
- Reject events with long URIs and data URIs plausible/analytics#2536
- Always show direct traffic in sources reports plausible/analytics#2531
+## Fixed
+- Cascade delete sent_renewal_notifications table when user is deleted plausible/analytics#2549
+
## v1.5.1 - 2022-12-06
### Fixed
diff --git a/priv/repo/migrations/20221228123226_cascade_delete_sent_renewal_notifications.exs b/priv/repo/migrations/20221228123226_cascade_delete_sent_renewal_notifications.exs
new file mode 100644
index 0000000000..15d4846343
--- /dev/null
+++ b/priv/repo/migrations/20221228123226_cascade_delete_sent_renewal_notifications.exs
@@ -0,0 +1,11 @@
+defmodule Plausible.Repo.Migrations.CascadeDeleteSentRenewalNotifications do
+ use Ecto.Migration
+
+ def change do
+ drop constraint("sent_renewal_notifications", "sent_renewal_notifications_user_id_fkey")
+
+ alter table(:sent_renewal_notifications) do
+ modify :user_id, references(:users, on_delete: :delete_all), null: false
+ end
+ end
+end
diff --git a/test/plausible_web/controllers/auth_controller_test.exs b/test/plausible_web/controllers/auth_controller_test.exs
index 7da7c544f8..fd2211ece3 100644
--- a/test/plausible_web/controllers/auth_controller_test.exs
+++ b/test/plausible_web/controllers/auth_controller_test.exs
@@ -677,6 +677,13 @@ defmodule PlausibleWeb.AuthControllerTest do
}
])
+ Repo.insert_all("sent_renewal_notifications", [
+ %{
+ user_id: user.id,
+ timestamp: NaiveDateTime.utc_now()
+ }
+ ])
+
insert(:google_auth, site: site, user: user)
insert(:subscription, user: user, status: "deleted")