{"record":{"id":"4bc64d7e30d5bcce","repo":"plandex-ai/plandex","slug":"error-getting-org-owner-role-id-v-4bc64d","errorCode":null,"errorMessage":"error getting org owner role id: %v","messagePattern":"error getting org owner role id: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app/server/db/rbac_helpers.go","lineNumber":15,"sourceCode":"package db\n\nimport (\n\t\"fmt\"\n\t\"log\"\n)\n\nvar orgOwnerRoleId string\nvar orgMemberRoleId string\n\nfunc GetOrgOwnerRoleId() (string, error) {\n\tif orgOwnerRoleId == \"\" {\n\t\terr := cacheOrgOwnerRoleId()\n\t\tif err != nil {\n\t\t\treturn \"\", fmt.Errorf(\"error getting org owner role id: %v\", err)\n\t\t}\n\t}\n\n\tif orgOwnerRoleId == \"\" {\n\t\treturn \"\", fmt.Errorf(\"org owner role id is empty\")\n\t}\n\n\treturn orgOwnerRoleId, nil\n}\n\nfunc GetOrgMemberRoleId() (string, error) {\n\tif orgMemberRoleId == \"\" {\n\t\terr := cacheOrgMemberRoleId()\n\t\tif err != nil {\n\t\t\treturn \"\", fmt.Errorf(\"error getting org member role id: %v\", err)\n\t\t}\n\t}\n","sourceCodeStart":1,"sourceCodeEnd":33,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/server/db/rbac_helpers.go#L1-L33","documentation":"GetOrgOwnerRoleId is a memoized lookup of the 'owner' org_roles row id. When the cached global orgOwnerRoleId is empty it calls cacheOrgOwnerRoleId, and if that DB query (Conn.Get on 'SELECT id FROM org_roles WHERE name = owner') fails, the underlying error is wrapped with this message. It means the role id could not be resolved from the database.","triggerScenarios":"Calling CreateOrg, AddToOrgForDomain or DeleteOrgUserHandler when the org_roles table is missing, has no 'owner' row, the DB connection is down, or Conn was not initialized before the first call.","commonSituations":"Fresh database created without role seed data; DB migrations not run; wrong DATABASE_URL pointing at an empty/uninitialized database; transient DB outage or connection-pool exhaustion at startup.","solutions":["Run the schema migrations/seed that insert the 'owner' row into org_roles","Verify the DB connection (Conn) is initialized via MustInitDb before any org operations","Check DATABASE_URL / connectivity with a direct psql query: SELECT id FROM org_roles WHERE name = 'owner';","Inspect the wrapped inner error (%v) for sql.ErrNoRows vs connection errors to decide between seed-data and connectivity fixes"],"exampleFix":"// before\nrole, err := GetOrgOwnerRoleId()\nif err != nil { return err }\n// after\nif err := CacheOrgRoleIds(); err != nil {\n\tlog.Fatalf(\"startup: org role ids unavailable: %v\", err)\n}\nrole, err := GetOrgOwnerRoleId()","handlingStrategy":"try-catch","validationCode":"// before calling CreateOrg / AddToOrgForDomain\nrows, err := db.Query(\"SELECT count(*) FROM org_roles WHERE name = 'owner'\")\nif err != nil || singleInt(rows) == 0 {\n\treturn fmt.Errorf(\"org_roles not seeded; run migrations\")\n}","typeGuard":"func hasOwnerRole(ctx context.Context, db *sql.DB) bool {\n\tvar n int\n\tif err := db.QueryRowContext(ctx, \"SELECT count(*) FROM org_roles WHERE name = 'owner'\").Scan(&n); err != nil {\n\t\treturn false\n\t}\n\treturn n > 0\n}","tryCatchPattern":"ownerRoleId, err := GetOrgOwnerRoleId()\nif err != nil {\n\tvar noRows = strings.Contains(err.Error(), \"sql: no rows\")\n\tif noRows {\n\t\treturn fmt.Errorf(\"org_roles seed data missing: %w\", err)\n\t}\n\treturn fmt.Errorf(\"database unavailable: %w\", err)\n}","preventionTips":["Run CacheOrgRoleIds() via MustInitDb and fail fast at startup","Keep role seed rows in versioned migrations so every environment has them","Health-check the DB (ping + role lookup) in readiness probes"],"tags":["database","sql","rbac","cache"],"backgroundTag":"missing-db-seed-data","analyzedSha":"e2d772072efadbe41d2946d97d79be55532dbab5","analyzedAt":"2026-09-05T20:56:53.631Z","contentChangedAt":"2026-09-05T20:56:53.631Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}