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))