Repository navigation
Add find_orphaned_dbs() / clean_testdb(orphaned=True) - #34
Merged
Merged
Conversation
Adds per-repo orphaned test-DB cleanup to pgdevkit, so a project can find/drop Postgres test DBs left behind by branches whose git worktree no longer exists, without a separate tool reimplementing the naming algorithm. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Adds pgdevkit.testdb.find_orphaned_dbs() and clean_testdb(orphaned=True) (plus `pgdb testdb list-orphaned` / `clean --orphaned`), so a project can find/drop Postgres (and MSSQL) test DBs whose branch no longer has a live git worktree, without a separate tool (e.g. bdt) reimplementing pgdevkit's naming algorithm to do the same thing. - naming.py: live_worktree_branches() parses `git worktree list --porcelain`, treating a detached-HEAD worktree as branch "HEAD" (matching current_branch()'s own literal output for one) so CI-style detached checkouts aren't misreported as orphaned; expected_db_names() maps live branches to the DB names they own. - config.py: new `[tool.pgdevkit].extra_db_suffixes` lets a repo teach orphan detection about its own sibling DBs (e.g. CCMT2's "_onetrade") without pgdevkit needing to know why they exist. - api.py / mssql/api.py: shared `_dbs_with_prefix` helper (used by both `clean_testdb(all=True)` and the new orphaned path); clean_testdb() gains an `orphaned` flag, mutually exclusive with `all`. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
aersam
force-pushed
the
orphaned-testdb-cleanup
branch
from
September 14, 2026 17:15
eed9948 to
11d1dd3
Compare
aersam
marked this pull request as ready for review
September 14, 2026 17:34
3 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
find_orphaned_dbs(project_root=None): diffs this project's live git worktrees against actual Postgres DBs matching the project's name-slug prefix, returning DBs with no matching live worktreeclean_testdb()gains anorphaned=Trueflag (mutually exclusive withall=True)pgdb testdb list-orphaned(dry-run) andpgdb testdb clean --orphaned[tool.pgdevkit].extra_db_suffixesconfig lets a consumer repo (e.g. CCMT2's_onetradesibling DB) teach orphan detection about its own sibling DBs, without pgdevkit hardcoding repo-specific conventionsTest plan
ty check pgdevkitcleanpytest tests/184/184 pass (49 podman-gated skipped in this sandbox; called those functions directly against this sandbox's native Postgres for live end-to-end confidence, including detached-HEAD and manually-deleted-worktree scenarios)/code-reviewcaught and fixed two real bugs: detached-HEAD worktrees were misclassified as orphaned (would have dropped a live DB out from under a CI checkout); deduplicated LIKE-prefix-escaping logic shared between postgres/mssql backends🤖 Generated with Claude Code