From f6b0700ea544c4e36a4cdc11cfa4f7881ddf0570 Mon Sep 17 00:00:00 2001 From: Mauricio Siu Date: Mon, 3 Aug 2026 03:42:27 -0600 Subject: [PATCH] fix(application): remove preview deployments when deleting an application --- apps/dokploy/server/api/routers/application.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/apps/dokploy/server/api/routers/application.ts b/apps/dokploy/server/api/routers/application.ts index e1bbedcb9..b6e2a3ee4 100644 --- a/apps/dokploy/server/api/routers/application.ts +++ b/apps/dokploy/server/api/routers/application.ts @@ -4,6 +4,7 @@ import { deleteAllMiddlewares, findApplicationById, findEnvironmentById, + findPreviewDeploymentsByApplicationId, findProjectById, getAccessibleServerIds, getApplicationStats, @@ -16,6 +17,7 @@ import { removeDeployments, removeDirectoryCode, removeMonitoringDirectory, + removePreviewDeployment, removeService, removeTraefikConfig, startService, @@ -234,6 +236,15 @@ export const applicationRouter = createTRPCRouter({ }); } + const previewDeploymentsList = + await findPreviewDeploymentsByApplicationId(input.applicationId); + + for (const previewDeployment of previewDeploymentsList) { + try { + await removePreviewDeployment(previewDeployment.previewDeploymentId); + } catch (_) {} + } + const result = await db .delete(applications) .where(eq(applications.applicationId, input.applicationId))