Skip to content

Commit 49a189f

Browse files
authored
Merge pull request #3728 from Dokploy/3722-deleted-an-environment-and-all-the-services-werent-deleted
feat(environment): add service check before environment deletion
2 parents 24010af + 7e8d3b7 commit 49a189f

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

packages/server/src/services/environment.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,18 @@ export const findEnvironmentsByProjectId = async (projectId: string) => {
101101
return projectEnvironments;
102102
};
103103

104+
const environmentHasServices = (env: Awaited<ReturnType<typeof findEnvironmentById>>) => {
105+
return (
106+
(env.applications?.length ?? 0) > 0 ||
107+
(env.compose?.length ?? 0) > 0 ||
108+
(env.mariadb?.length ?? 0) > 0 ||
109+
(env.mongo?.length ?? 0) > 0 ||
110+
(env.mysql?.length ?? 0) > 0 ||
111+
(env.postgres?.length ?? 0) > 0 ||
112+
(env.redis?.length ?? 0) > 0
113+
);
114+
};
115+
104116
export const deleteEnvironment = async (environmentId: string) => {
105117
const currentEnvironment = await findEnvironmentById(environmentId);
106118
if (currentEnvironment.isDefault) {
@@ -109,6 +121,13 @@ export const deleteEnvironment = async (environmentId: string) => {
109121
message: "You cannot delete the default environment",
110122
});
111123
}
124+
if (environmentHasServices(currentEnvironment)) {
125+
throw new TRPCError({
126+
code: "BAD_REQUEST",
127+
message:
128+
"Cannot delete environment: it has active services. Delete all services first.",
129+
});
130+
}
112131
const deletedEnvironment = await db
113132
.delete(environments)
114133
.where(eq(environments.environmentId, environmentId))

0 commit comments

Comments
 (0)