mirror of
https://github.com/Dokploy/dokploy.git
synced 2026-06-15 20:25:23 +02:00
feat(environment): add service check before environment deletion
- Implemented a new function to verify if an environment has active services before allowing its deletion. This prevents accidental deletion of environments that are still in use.
This commit is contained in:
@@ -101,6 +101,18 @@ export const findEnvironmentsByProjectId = async (projectId: string) => {
|
|||||||
return projectEnvironments;
|
return projectEnvironments;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const environmentHasServices = (env: Awaited<ReturnType<typeof findEnvironmentById>>) => {
|
||||||
|
return (
|
||||||
|
(env.applications?.length ?? 0) > 0 ||
|
||||||
|
(env.compose?.length ?? 0) > 0 ||
|
||||||
|
(env.mariadb?.length ?? 0) > 0 ||
|
||||||
|
(env.mongo?.length ?? 0) > 0 ||
|
||||||
|
(env.mysql?.length ?? 0) > 0 ||
|
||||||
|
(env.postgres?.length ?? 0) > 0 ||
|
||||||
|
(env.redis?.length ?? 0) > 0
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
export const deleteEnvironment = async (environmentId: string) => {
|
export const deleteEnvironment = async (environmentId: string) => {
|
||||||
const currentEnvironment = await findEnvironmentById(environmentId);
|
const currentEnvironment = await findEnvironmentById(environmentId);
|
||||||
if (currentEnvironment.isDefault) {
|
if (currentEnvironment.isDefault) {
|
||||||
@@ -109,6 +121,13 @@ export const deleteEnvironment = async (environmentId: string) => {
|
|||||||
message: "You cannot delete the default environment",
|
message: "You cannot delete the default environment",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
if (environmentHasServices(currentEnvironment)) {
|
||||||
|
throw new TRPCError({
|
||||||
|
code: "BAD_REQUEST",
|
||||||
|
message:
|
||||||
|
"Cannot delete environment: it has active services. Delete all services first.",
|
||||||
|
});
|
||||||
|
}
|
||||||
const deletedEnvironment = await db
|
const deletedEnvironment = await db
|
||||||
.delete(environments)
|
.delete(environments)
|
||||||
.where(eq(environments.environmentId, environmentId))
|
.where(eq(environments.environmentId, environmentId))
|
||||||
|
|||||||
Reference in New Issue
Block a user