Skip to content

feat(environment): add service check before environment deletion#3728

Merged
Siumauricio merged 1 commit intocanaryfrom
3722-deleted-an-environment-and-all-the-services-werent-deleted
Feb 17, 2026
Merged

feat(environment): add service check before environment deletion#3728
Siumauricio merged 1 commit intocanaryfrom
3722-deleted-an-environment-and-all-the-services-werent-deleted

Conversation

@Siumauricio
Copy link
Contributor

@Siumauricio Siumauricio commented Feb 17, 2026

  • 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.

What is this PR about?

Please describe in a short paragraph what this PR is about.

Checklist

Before submitting this PR, please make sure that:

  • You created a dedicated branch based on the canary branch.
  • You have read the suggestions in the CONTRIBUTING.md file https://github.com/Dokploy/dokploy/blob/canary/CONTRIBUTING.md#pull-request
  • You have tested this PR in your local instance. If you have not tested it yet, please do so before submitting. This helps avoid wasting maintainers' time reviewing code that has not been verified by you.

Issues related (if applicable)

closes #3722

Screenshots (if applicable)

Greptile Summary

This PR adds server-side validation to prevent deletion of environments that still contain active services (applications, compose, mariadb, mongo, mysql, postgres, redis). A new environmentHasServices helper checks if any service arrays are non-empty, and deleteEnvironment throws a BAD_REQUEST error if services exist.

  • Adds environmentHasServices helper function using Awaited<ReturnType<typeof findEnvironmentById>> for type safety
  • Integrates the check into deleteEnvironment, throwing a clear error message instructing users to delete services first
  • Complements the existing client-side check in advanced-environment-selector.tsx (defense in depth)
  • Notably, all service tables already have onDelete: "cascade" on the environmentId FK — this PR prevents the accidental cascade deletion of services when an environment is deleted directly (e.g., via API bypass of the frontend)

Confidence Score: 5/5

  • This PR is safe to merge — it adds a defensive server-side guard that prevents accidental data loss.
  • The change is minimal (two small additions to a single file), logically correct, and consistent with the existing frontend behavior. The environmentHasServices function properly checks all seven service types that match the DB schema relations. The error handling follows existing patterns in the codebase. No regressions are expected since this only adds a new guard before deletion — existing callers that pass environments without services are unaffected.
  • No files require special attention.

Last reviewed commit: 7e8d3b7

- 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.
@Siumauricio Siumauricio linked an issue Feb 17, 2026 that may be closed by this pull request
@Siumauricio Siumauricio merged commit 49a189f into canary Feb 17, 2026
3 of 4 checks passed
Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 file reviewed, no comments

Edit Code Review Agent Settings | Greptile

@LeOndaz
Copy link

LeOndaz commented Feb 17, 2026

that was quick thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Deleted an environment, and all the services weren't deleted

2 participants