{"record":{"id":"d9163dcf2d5787d4","repo":"mastra-ai/mastra","slug":"attaching-a-database-requires-the-admin-role-in-yo","errorCode":null,"errorMessage":"Attaching a database requires the admin role in your organization. Ask an org admin to run `create-factory`, or attach a database from the dashboard.","messagePattern":"Attaching a database requires the admin role in your organization\\. Ask an org admin to run `create-factory`, or attach a database from the dashboard\\.","errorType":"http","errorClass":"PlatformApiError","httpStatus":403,"severity":"error","filePath":"mastracode/mastra-factory/src/platform.ts","lineNumber":145,"sourceCode":"  regionId,\n}: {\n  token: string;\n  orgId: string;\n  projectId: string;\n  name: string;\n  regionId: string;\n}): Promise<AttachedDatabase> {\n  const res = await platformFetch(\n    `${MASTRA_PLATFORM_API_URL}/v1/server/projects/${encodeURIComponent(projectId)}/databases`,\n    {\n      method: 'POST',\n      headers: { ...authHeaders(token, orgId), 'Content-Type': 'application/json' },\n      body: JSON.stringify({ kind: 'neon', name, regionId }),\n    },\n  );\n  if (!res.ok) {\n    if (res.status === 403) {\n      throw new PlatformApiError(\n        403,\n        `Attaching a database requires the admin role in your organization. Ask an org admin to run \\`create-factory\\`, or attach a database from the dashboard.`,\n      );\n    }\n    throw new PlatformApiError(res.status, `Failed to attach Neon database — ${await extractError(res)}`);\n  }\n  const body = (await res.json()) as AttachDatabaseResponse;\n  return body.database;\n}\n\n/** GET /v1/server/projects/:id/databases/:dbId — status poll target. */\nexport async function getDatabaseStatus({\n  token,\n  orgId,\n  projectId,\n  databaseId,\n  signal,\n}: {","sourceCodeStart":127,"sourceCodeEnd":163,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/mastracode/mastra-factory/src/platform.ts#L127-L163","documentation":"attachNeonDatabase attaches a Neon database to a server project via the platform API. A 403 response is mapped to this explicit, actionable PlatformApiError instead of the generic attach-failure message, because attaching a database requires the admin role in the organization.","triggerScenarios":"POST to attach a `{ kind: 'neon', name, regionId }` database returns HTTP 403 — i.e. the authenticated user is a member of the org but not an admin/owner.","commonSituations":"Developer on a team plan running create-factory with a non-admin account; role downgraded after SSO/invites changed; token minted for a member-scoped API key; using --attach mode instead of full provisioning that an admin would run.","solutions":["Ask an organization admin to run `create-factory` for you.","Attach the database from the Mastra Platform dashboard, then rerun the CLI pointing at the existing database.","Re-authenticate with an account that has the admin role in the target org.","Verify with the org owner that your role hasn't changed recently."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"const me = await getOrgMember({ token, orgId, userId: currentUserId });\nif (me.role !== 'admin' && me.role !== 'owner') {\n  throw new Error('Requires org admin role — ask an admin to run create-factory or attach the DB via dashboard.');\n}","typeGuard":null,"tryCatchPattern":"try {\n  await attachNeonDatabase(opts);\n} catch (err) {\n  if (err instanceof PlatformApiError && err.status === 403) {\n    console.error('Your account lacks the org admin role. Ask an admin to run create-factory or attach the DB from the dashboard.');\n    process.exit(1);\n  }\n  throw err;\n}","preventionTips":["Check your org role before running provisioning commands.","Keep at least one admin account available for infrastructure setup.","Use the dashboard for database attach when the CLI account is member-scoped.","Re-verify role after SSO or team changes."],"tags":["http-403","permissions","rbac","platform-api"],"backgroundTag":"insufficient-permissions","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}