Skip to main content

migrate_user_schema

Function migrate_user_schema 

Source
pub async fn migrate_user_schema(db: &Db) -> Result<()>
Expand description

Idempotent schema upgrade for the 5-tier role hierarchy + demo + profile columns. Safe to call repeatedly; safe on a fresh DB and on a legacy 'admin'-roled DB.

Order is load-bearing:

  1. Rename existing 'admin' rows to 'administrator' BEFORE the CHECK constraint is added, otherwise the constraint would reject the row.
  2. Add the demo columns idempotently.
  3. Add the CHECK constraint conditionally (PG has no IF NOT EXISTS for CHECK constraints, so we guard via pg_constraint).
  4. Add the indexes.
  5. Add the profile-display columns.