{"record":{"id":"fa15a6bd56d6c695","repo":"Dokploy/dokploy","slug":"bad-request-fa15a6","errorCode":"BAD_REQUEST","errorMessage":"Error input: Inserting Postgres database","messagePattern":"Error input: Inserting Postgres database","errorType":"exception","errorClass":"TRPCError","httpStatus":400,"severity":"error","filePath":"apps/dokploy/server/api/routers/postgres.ts","lineNumber":121,"sourceCode":"\t\t\t\t\tserviceId: newPostgres.postgresId,\n\t\t\t\t\tserviceType: \"postgres\",\n\t\t\t\t\tvolumeName: `${newPostgres.appName}-data`,\n\t\t\t\t\tmountPath: mountPath,\n\t\t\t\t\ttype: \"volume\",\n\t\t\t\t});\n\n\t\t\t\tawait audit(ctx, {\n\t\t\t\t\taction: \"create\",\n\t\t\t\t\tresourceType: \"service\",\n\t\t\t\t\tresourceId: newPostgres.postgresId,\n\t\t\t\t\tresourceName: newPostgres.appName,\n\t\t\t\t});\n\t\t\t\treturn newPostgres;\n\t\t\t} catch (error) {\n\t\t\t\tif (error instanceof TRPCError) {\n\t\t\t\t\tthrow error;\n\t\t\t\t}\n\t\t\t\tthrow new TRPCError({\n\t\t\t\t\tcode: \"BAD_REQUEST\",\n\t\t\t\t\tmessage: \"Error input: Inserting Postgres database\",\n\t\t\t\t\tcause: error,\n\t\t\t\t});\n\t\t\t}\n\t\t}),\n\tone: protectedProcedure\n\t\t.input(apiFindOnePostgres)\n\t\t.query(async ({ input, ctx }) => {\n\t\t\tawait checkServiceAccess(ctx, input.postgresId, \"read\");\n\n\t\t\tconst postgres = await findPostgresById(input.postgresId);\n\t\t\tif (\n\t\t\t\tpostgres.environment.project.organizationId !==\n\t\t\t\tctx.session.activeOrganizationId\n\t\t\t) {\n\t\t\t\tthrow new TRPCError({\n\t\t\t\t\tcode: \"UNAUTHORIZED\",","sourceCodeStart":103,"sourceCodeEnd":139,"githubUrl":"https://github.com/Dokploy/dokploy/blob/546686ea3587f12ec5652217dedd9f7960fb6d15/apps/dokploy/server/api/routers/postgres.ts#L103-L139","documentation":"Catch-all BAD_REQUEST in createPostgres: the underlying database insert (or setup logic) threw a non-TRPCError. The original error is attached as cause. Common causes are Drizzle ORM constraint violations (duplicate appName/postgresId), invalid enum values, or DB connectivity issues.","triggerScenarios":"Any exception during postgres creation after the auth checks — duplicate unique key (appName already used), malformed input that passed Zod but violates DB constraints, or the database being unreachable.","commonSituations":"Recreating a Postgres with the same app name after an incomplete deletion; DB schema out of sync after a Dokploy upgrade; transient Postgres downtime on the control plane.","solutions":["Inspect error.cause for the real driver error (unique constraint, FK, connection refused)","If it's a duplicate appName, choose a different name or fully remove the old record","Run Dokploy migrations / restart if the DB schema is stale","Retry after confirming the Dokploy internal database is healthy"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  await api.postgres.create.mutate(input);\n} catch (e) {\n  const cause = e.cause ?? e.data?.cause;\n  if (String(cause).includes('unique')) throw new Error('Name already in use');\n  throw e;\n}","preventionTips":["Always inspect error.cause for the real DB error","Use unique app names per instance"],"tags":["dokploy","postgres","database-insert","drizzle"],"backgroundTag":"database-insert-failed","analyzedSha":"546686ea3587f12ec5652217dedd9f7960fb6d15","analyzedAt":"2026-08-27T05:18:58.095Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}