{"record":{"id":"caca3ca3526844be","repo":"Dokploy/dokploy","slug":"bad-request-caca3c","errorCode":"BAD_REQUEST","errorMessage":"Error input: Inserting mariadb database","messagePattern":"Error input: Inserting mariadb database","errorType":"exception","errorClass":"TRPCError","httpStatus":400,"severity":"error","filePath":"packages/server/src/services/mariadb.ts","lineNumber":49,"sourceCode":"\t}\n\n\tconst newMariadb = await db\n\t\t.insert(mariadb)\n\t\t.values({\n\t\t\t...input,\n\t\t\tdatabasePassword: input.databasePassword\n\t\t\t\t? input.databasePassword\n\t\t\t\t: generatePassword(),\n\t\t\tdatabaseRootPassword: input.databaseRootPassword\n\t\t\t\t? input.databaseRootPassword\n\t\t\t\t: generatePassword(),\n\t\t\tappName,\n\t\t})\n\t\t.returning()\n\t\t.then((value) => value[0]);\n\n\tif (!newMariadb) {\n\t\tthrow new TRPCError({\n\t\t\tcode: \"BAD_REQUEST\",\n\t\t\tmessage: \"Error input: Inserting mariadb database\",\n\t\t});\n\t}\n\n\treturn newMariadb;\n};\n\n// https://github.com/drizzle-team/drizzle-orm/discussions/1483#discussioncomment-7523881\nexport const findMariadbById = async (mariadbId: string) => {\n\tconst result = await db.query.mariadb.findFirst({\n\t\twhere: eq(mariadb.mariadbId, mariadbId),\n\t\twith: {\n\t\t\tenvironment: {\n\t\t\t\twith: {\n\t\t\t\t\tproject: true,\n\t\t\t\t},\n\t\t\t},","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/Dokploy/dokploy/blob/546686ea3587f12ec5652217dedd9f7960fb6d15/packages/server/src/services/mariadb.ts#L31-L67","documentation":"Thrown by createMariadb when the Drizzle INSERT into the mariadb table with .returning() returns no row. The insert failed at the database level (constraint violation, schema mismatch, connectivity) despite passing the uniqueness pre-check.","triggerScenarios":"Calling createMariadb where the INSERT hits a NOT NULL/enum/foreign-key violation, or the connection drops between the uniqueness check and the insert (a race with a concurrent create also surfaces here).","commonSituations":"Concurrent provisioning scripts racing on the same name (check passes for both, insert fails for one), schema drift after upgrade, missing defaults on new columns.","solutions":["Inspect server logs for the underlying Postgres error","Handle the race: if the row actually exists, treat it as a 409 and reuse/rename","Run migrations to sync schema after upgrades"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { await createMariadb(input); } catch (e) { if (e.shape?.data?.code === 'BAD_REQUEST') { const apps = await listApps(); if (apps.some(a => a.name === name)) throw new ConflictError(); throw e; } }","preventionTips":["Serialize provisioning calls per appName to avoid races","Keep DB schema migrations current"],"tags":["database","drizzle-orm","mariadb","insert","race-condition"],"backgroundTag":"database-insert-returned-no-row","analyzedSha":"546686ea3587f12ec5652217dedd9f7960fb6d15","analyzedAt":"2026-08-27T05:18:58.095Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}