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:
- Rename existing
'admin'rows to'administrator'BEFORE the CHECK constraint is added, otherwise the constraint would reject the row. - Add the demo columns idempotently.
- Add the CHECK constraint conditionally (PG has no
IF NOT EXISTSfor CHECK constraints, so we guard viapg_constraint). - Add the indexes.
- Add the profile-display columns.