{"record":{"id":"3db9279f1bfc3339","repo":"Dokploy/dokploy","slug":"internal-server-error-3db927","errorCode":"INTERNAL_SERVER_ERROR","errorMessage":"Failed to move postgres","messagePattern":"Failed to move postgres","errorType":"exception","errorClass":"TRPCError","httpStatus":500,"severity":"error","filePath":"apps/dokploy/server/api/routers/postgres.ts","lineNumber":494,"sourceCode":"\t\t\t\ttargetEnvironmentId: z.string(),\n\t\t\t}),\n\t\t)\n\t\t.mutation(async ({ input, ctx }) => {\n\t\t\tawait checkServicePermissionAndAccess(ctx, input.postgresId, {\n\t\t\t\tservice: [\"create\"],\n\t\t\t});\n\n\t\t\tconst updatedPostgres = await db\n\t\t\t\t.update(postgresTable)\n\t\t\t\t.set({\n\t\t\t\t\tenvironmentId: input.targetEnvironmentId,\n\t\t\t\t})\n\t\t\t\t.where(eq(postgresTable.postgresId, input.postgresId))\n\t\t\t\t.returning()\n\t\t\t\t.then((res) => res[0]);\n\n\t\t\tif (!updatedPostgres) {\n\t\t\t\tthrow new TRPCError({\n\t\t\t\t\tcode: \"INTERNAL_SERVER_ERROR\",\n\t\t\t\t\tmessage: \"Failed to move postgres\",\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tawait audit(ctx, {\n\t\t\t\taction: \"move\",\n\t\t\t\tresourceType: \"service\",\n\t\t\t\tresourceId: updatedPostgres.postgresId,\n\t\t\t\tresourceName: updatedPostgres.appName,\n\t\t\t});\n\t\t\treturn updatedPostgres;\n\t\t}),\n\trebuild: protectedProcedure\n\t\t.input(apiRebuildPostgres)\n\t\t.mutation(async ({ input, ctx }) => {\n\t\t\tawait checkServicePermissionAndAccess(ctx, input.postgresId, {\n\t\t\t\tdeployment: [\"create\"],","sourceCodeStart":476,"sourceCodeEnd":512,"githubUrl":"https://github.com/Dokploy/dokploy/blob/546686ea3587f12ec5652217dedd9f7960fb6d15/apps/dokploy/server/api/routers/postgres.ts#L476-L512","documentation":"The move-to-environment/project flow updates the postgres row via a Drizzle update ... returning() and the result is empty, meaning no row matched postgresId — the Postgres no longer exists at move time.","triggerScenarios":"postgres.move called with a deleted postgresId, or the row is deleted concurrently (e.g. cleanup task) during the move.","commonSituations":"Moving a database whose project/environment was deleted first; double-submitted move where the first attempt removed state.","solutions":["Verify the Postgres exists and its environment/project targets are valid before moving","Retry the move with a fresh postgresId from a re-query","Avoid concurrent delete+move operations on the same resource"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if (!(await api.postgres.one.query({ postgresId }))) throw new Error('Postgres missing before move');","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Don't run concurrent move and delete operations on one resource"],"tags":["dokploy","move","not-found","postgres"],"backgroundTag":"resource-not-found","analyzedSha":"546686ea3587f12ec5652217dedd9f7960fb6d15","analyzedAt":"2026-08-27T05:18:58.095Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}