From 13b897c01deee0f9509e0cd3e17a77804fa7ba3c Mon Sep 17 00:00:00 2001 From: Mauricio Siu <47042324+Siumauricio@users.noreply.github.com> Date: Mon, 3 Aug 2026 03:43:17 -0600 Subject: [PATCH] Merge pull request #4959 from Dokploy/fix/cleanup-preview-deployments-on-app-delete fix(application): remove preview deployments when deleting an application (cherry picked from commit 056b6983db6387ece925a60661d8fcd4b45f7d30) --- 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))