Skip to content

feat: add --environment flag to sqlmesh janitor for scoped cleanup#5810

Draft
mday-io wants to merge 1 commit into
SQLMesh:mainfrom
mday-io:mday-io/feature/janitor-environment-flag
Draft

feat: add --environment flag to sqlmesh janitor for scoped cleanup#5810
mday-io wants to merge 1 commit into
SQLMesh:mainfrom
mday-io:mday-io/feature/janitor-environment-flag

Conversation

@mday-io
Copy link
Copy Markdown
Contributor

@mday-io mday-io commented May 22, 2026

Description

Add an --environment / -e flag to sqlmesh janitor that scopes cleanup to a single named environment, and fix sqlmesh invalidate <env> --sync to only clean up the named environment rather than all currently-expired environments.

New flag: sqlmesh janitor --environment <name> removes views, schemas, and state records for the named environment only. If the environment is not expired or does not exist, a warning is emitted. Global snapshot expiration and interval compaction are skipped when this flag is set — those operations are cross-environment and cannot be safely scoped to a single one.

Bug fix: sqlmesh invalidate <env> --sync previously called _cleanup_environments() with no filter after marking the target environment expired, which caused all other currently-expired environments to be deleted as a side effect. It now scopes the cleanup to the named environment only.

Test Plan

  • Tested manually against the sushi example project using --gateway duckdb_persistent with two environments (dev1, dev2). Invalidating dev1 and running sqlmesh janitor --environment dev1 cleaned up dev1 while leaving dev2 untouched.
  • Verified the warning message fires when targeting an environment that is not expired or does not exist.

Checklist

  • I have run make style and fixed any issues
  • I have added tests for my changes (if applicable)
  • All existing tests pass (make fast-test)
  • My commits are signed off (git commit -s) per the DCO

@mday-io mday-io force-pushed the mday-io/feature/janitor-environment-flag branch from df7b55c to 00992be Compare May 22, 2026 21:28
@mday-io mday-io marked this pull request as draft May 22, 2026 21:34
Signed-off-by: Michael Day <michael.day@cloudkitchens.com>
Signed-off-by: mday-io <mdaytn@gmail.com>
@mday-io mday-io force-pushed the mday-io/feature/janitor-environment-flag branch from 00992be to e3ca817 Compare May 22, 2026 21:42
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.

1 participant