PhoenixKit.Migrations.Postgres.V191 (phoenix_kit v2.29.1)

Copy Markdown View Source

V191: who added a user.

Adds phoenix_kit_users.created_by_uuid uuid NULL — the account that created this user by hand from the admin panel. NULL means the user signed themselves up (registration form, magic link, OAuth, guest checkout), or was added before this column existed and left no trace.

  • Foreign key, ON DELETE SET NULL — the same shape as organization_uuid. Deleting the admin who added someone must not delete, or block deleting, the people they added.
  • Index — ON DELETE SET NULL makes Postgres look up every row pointing at a deleted user; without one that is a full scan of phoenix_kit_users per user deletion.
  • Backfill — the admin form has logged a user.created activity with metadata.method = 'manual' and the creating admin as actor_uuid since the Activity feed shipped. Those entries seed the column, so users added before this version still show who added them — as far back as activity_retention_days kept the entry. Only an actor that still exists is copied, and a value already present is never overwritten, so the statement is safe to re-run.

The column is written only by PhoenixKit.Users.Auth.admin_create_user/2 and is never cast from params: a public registration form cannot claim to have been added by someone.

Summary

Functions

Rolls V191 back: drops the column (its index and foreign key go with it).

Functions

down(opts)

Rolls V191 back: drops the column (its index and foreign key go with it).

Lossy: who added each user is lost, except for what the Activity feed still holds.

up(opts)