From ca2c1bb8ceffcc7ef367eac66c23530f7513b7aa Mon Sep 17 00:00:00 2001 From: MMD Date: Thu, 8 Oct 2026 11:04:39 +0330 Subject: [PATCH] fix(db): add missing 'supervisor' value to the user_role enum at startup CREATE TYPE ... EXCEPTION WHEN duplicate_object no-ops on existing types, so volumes created before 'supervisor' existed kept an enum without it and assigning the role 500'd: invalid input value for enum user_role: "supervisor". ALTER TYPE ... ADD VALUE IF NOT EXISTS is idempotent and safe on any volume. --- backend/app/db/init_db.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/backend/app/db/init_db.py b/backend/app/db/init_db.py index 062973e..4fe5ae3 100644 --- a/backend/app/db/init_db.py +++ b/backend/app/db/init_db.py @@ -420,6 +420,9 @@ async def ensure_rbac_schema(engine: AsyncEngine) -> None: volume — the RBAC model expects these and login 500s without them.""" stmts = ( "ALTER TABLE users ADD COLUMN IF NOT EXISTS username TEXT", + # The live user_role enum predates 'supervisor' — CREATE TYPE no-ops on + # an existing type, so without this ALTER, assigning the role 500s. + "ALTER TYPE user_role ADD VALUE IF NOT EXISTS 'supervisor'", "ALTER TABLE projects ADD COLUMN IF NOT EXISTS location TEXT DEFAULT ''", "ALTER TABLE projects ADD COLUMN IF NOT EXISTS project_manager TEXT DEFAULT ''", "ALTER TABLE projects ADD COLUMN IF NOT EXISTS planned_start DATE",