analytics/priv/repo/migrations/20230802081520_cascade_delete_user.exs
hq1 054d0655af
[pg migration] Delete account with multiple subscriptions (#3220)
* Migrate user deletion

So that subscriptions, google

* Make CRM deletion functional

* Preload subscriptions in an uniform manner
2023-08-02 13:45:49 +02:00

44 lines
1.2 KiB
Elixir

defmodule Plausible.Repo.Migrations.CascadeDeleteUser do
use Ecto.Migration
def up do
drop(constraint(:subscriptions, "subscriptions_user_id_fkey"))
alter table(:subscriptions) do
modify(:user_id, references(:users, on_delete: :delete_all), null: false)
end
drop(constraint(:site_memberships, "site_memberships_user_id_fkey"))
alter table(:site_memberships) do
modify(:user_id, references(:users, on_delete: :delete_all), null: false)
end
drop(constraint(:google_auth, "google_auth_user_id_fkey"))
alter table(:google_auth) do
modify(:user_id, references(:users, on_delete: :delete_all), null: false)
end
end
def down do
drop(constraint(:subscriptions, "subscriptions_user_id_fkey"))
alter table(:subscriptions) do
modify(:user_id, references(:users), null: false)
end
drop(constraint(:site_memberships, "site_memberships_user_id_fkey"))
alter table(:site_memberships) do
modify(:user_id, references(:users), null: false)
end
drop(constraint(:google_auth, "google_auth_user_id_fkey"))
alter table(:google_auth) do
modify(:user_id, references(:users), null: false)
end
end
end