Skip to content

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

Add `users.sso_domain_id` FK and alter `users.sso_integration_id` FK (#5464)

Adrian Gruntkowski7ccaebfee744
diff --git a/priv/repo/migrations/20250603125849_adjust_users_sso_constraints.exs b/priv/repo/migrations/20250603125849_adjust_users_sso_constraints.exs
new file mode 100644
index 0000000000..b558e4a09e
--- /dev/null
+++ b/priv/repo/migrations/20250603125849_adjust_users_sso_constraints.exs
@@ -0,0 +1,19 @@
+defmodule Plausible.Repo.Migrations.AdjustUsersSsoConstraints do
+ use Ecto.Migration
+
+ import Plausible.MigrationUtils
+
+ def change do
+ if enterprise_edition?() do
+ alter table(:users) do
+ add :sso_domain_id, references(:sso_domains, on_delete: :nothing), null: true
+
+ modify :sso_integration_id, references(:sso_integrations, on_delete: :nothing),
+ from: references(:sso_integrations, on_delete: :nilify_all),
+ null: true
+ end
+
+ create index(:users, [:sso_domain_id])
+ end
+ end
+end