Cleanup and Teardown - accelerate-data/migration-utility GitHub Wiki
Two cleanup operations remove resources created during the migration pipeline: /cleanup-worktrees for git worktrees and branches, and ad-migration teardown-sandbox for the throwaway test database.
Drops the active sandbox endpoint that was created by ad-migration setup-sandbox during test generation.
Run ad-migration teardown-sandbox after test generation is complete for all tables in the current batch. The sandbox is only needed while /generate-tests is actively executing stored procedures to capture ground truth. Once all test specs are written to test-specs/, the sandbox can be safely dropped.
- Reads
manifest.jsonto find theruntime.sandboxfield - Shows the user which database will be dropped and asks for confirmation (this is a destructive operation)
- Runs
test-harness sandbox-downto drop the database - Clears the
sandboxsection frommanifest.json
- The command requires explicit user confirmation before dropping the database
- If the database has already been dropped (e.g. manually), the command reports success rather than an error
- If no sandbox metadata exists in
manifest.json, the command stops and tells the user no sandbox exists
| Situation | Behavior |
|---|---|
| Drop succeeds | Sandbox section cleared from manifest, success reported |
| Database already gone | Reported as success, not an error |
| Connection error or permissions failure | Reports SANDBOX_DOWN_FAILED error with details |
| No sandbox metadata in manifest | Stops with message that no sandbox exists |
Scans git worktrees and local branches for merged PRs and removes them. Runs three passes in sequence.
Run /cleanup-worktrees after PRs have been merged. Batch commands create a worktree per invocation, and these accumulate over time. Periodic cleanup keeps the workspace tidy.
/cleanup-worktrees
/cleanup-worktrees <branch>
Pass 1 — Worktree cleanup
- Lists all worktrees via
git worktree list --porcelain - For each worktree branch, checks GitHub for a merged PR via
gh pr list --head <branch> --state merged - Classifies each worktree:
-
Merged PR found — remove worktree, delete local branch (
git branch -d), delete remote branch (git push origin --delete) - Open PR found — skipped ("PR still open")
- No PR found — skipped ("no PR found")
-
Merged PR found — remove worktree, delete local branch (
Pass 2 — Gone branch sweep
After the worktree cleanup, runs git fetch --prune then scans git branch -v for branches marked [gone] (remote tracking ref no longer exists). For each gone branch:
- If a merged PR exists: removes any associated worktree, then force-deletes the local branch (
git branch -D) - If no PR or open PR: skipped and reported
Branches already handled in Pass 1 are skipped.
Pass 3 — Remote-only sweep
Scans git branch -r for remote branches that have no local counterpart. For each:
- If a merged PR exists: deletes the remote branch (
git push origin --delete) - If no PR: skipped ("no PR found")
- If open PR: skipped ("PR still open")
Skips origin/HEAD, origin/main, and branches handled in Passes 1 or 2.
The command presents results in three separate sections:
cleanup-worktrees complete
Worktree cleanup:
✓ feature/scope-silver-dimcustomer cleaned (PR #42 merged)
- feature/profile-silver-dimcustomer skipped (PR #45 still open)
- feature/generate-model-old skipped (no PR found)
cleaned: 1 | skipped: 2
Gone branch sweep:
✓ feature/refactor-silver-dimcustomer cleaned (PR #43 merged)
- feature/wip-branch skipped (no PR found)
cleaned: 1 | skipped: 1
Remote-only sweep:
✓ feature/scope-silver-dimdate cleaned (PR #41 merged)
- feature/open-pr-branch skipped (PR still open)
cleaned: 1 | skipped: 1
Sections with no results are omitted from the output.
| Situation | Behavior |
|---|---|
git worktree remove fails |
Reports error, continues to next worktree |
git branch -d fails |
Branch not fully merged — reports warning, does not force delete |
git branch -D fails (gone branch) |
Reports error, continues |
git push origin --delete fails |
Reports error, continues |
| No worktrees found | Reports that there are no worktrees to clean up |
- Git Workflow -- how worktrees and branches are created
- Stage 3 Test Generation -- when the sandbox is used