feat: add wt and db CLI tools for worktree and database branching#915
feat: add wt and db CLI tools for worktree and database branching#915
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
This pull request has been ignored for the connected project Preview Branches by Supabase. |
1a902a7 to
67e793c
Compare
| 2. **Switch**: `ALTER DATABASE postgres RENAME TO wt_<old>; ALTER DATABASE wt_<new> RENAME TO postgres;` — since services hardcode `postgres`, renaming transparently switches which branch they see | ||
| 3. **Restart**: Bounce services to reconnect (~5 seconds) | ||
|
|
||
| This gives full isolation with a single Supabase stack. The only trade-off: one DB branch is "active" at a time. |
There was a problem hiding this comment.
too bad that we can't work on more than one in parallel but this is still pretty useful I'd say
There was a problem hiding this comment.
I see now that fully separate supabase stack for this is possible but v2. I like that idea so one can pick the level of isolation needed
There was a problem hiding this comment.
which plugin did you use to generate this file? I used superpowers but it didn't create me a brainstorm doc, just a plan.
There was a problem hiding this comment.
I like that you committed these files. It made it lot easier for me to review
There was a problem hiding this comment.
why do we need tsconfig for this?
tools/db.ts
Outdated
There was a problem hiding this comment.
I would maybe create a folder just for this tool and put all its files in there to separate from other tools. then I'd probably put lock and state files there too to reduce num of top level files (there's already so many of them which makes it harder to find things there)
There was a problem hiding this comment.
I like that you committed these files. It made it lot easier for me to review
| 2. **Switch**: `ALTER DATABASE postgres RENAME TO wt_<old>; ALTER DATABASE wt_<new> RENAME TO postgres;` — since services hardcode `postgres`, renaming transparently switches which branch they see | ||
| 3. **Restart**: Bounce services to reconnect (~5 seconds) | ||
|
|
||
| This gives full isolation with a single Supabase stack. The only trade-off: one DB branch is "active" at a time. |
There was a problem hiding this comment.
I see now that fully separate supabase stack for this is possible but v2. I like that idea so one can pick the level of isolation needed
| └── db.ts # Database branching CLI entry point (commander) | ||
| ``` | ||
|
|
||
| **Worktree location:** `.trees/` at project root (already in use for manual worktrees, gitignored via `.git/info/exclude` — move to `.gitignore`). `.claude/worktrees/` is a separate system managed by Claude Code and is not touched by `wt`. |
There was a problem hiding this comment.
couldn't we use the same folder? my understanding is that claude is also just wrapping git worktrees so should be the same
| 3. Terminate any remaining connections to `postgres` AND `wt_<target>` | ||
| ↳ ALTER DATABASE RENAME fails if any connections exist. | ||
| Supabase stop handles most, but stray connections (dev servers, psql sessions) may linger. | ||
| 4. RENAME postgres → wt_<temp_sentinel> -- Step A |
There was a problem hiding this comment.
do you know why is this temp_sentinel needed?
|
|
||
| ### Dev Server Port Configuration | ||
|
|
||
| `app/server.ts` currently hardcodes port 3000. Modify to read from `PORT` env var: |
There was a problem hiding this comment.
this doesn't seem to be done yet
| fi | ||
| ``` | ||
|
|
||
| This replaces the current `bun run db:generate-types` hook entry with a script that handles branching. |
There was a problem hiding this comment.
how does it replace it? I am not sure I understand. the devenv.nix still has:
git-hooks.hooks.generate-db-types = {
enable = true;
name = "Generate database types from local db";
entry = "bun run db:generate-types";
};
| - [ ] `wt list` shows accurate worktree table | ||
| - [ ] Failed setups clean up after themselves | ||
|
|
||
| ### Phase 4: Integration — Dev Server, Hooks, devenv |
There was a problem hiding this comment.
I see this now. This was not implemented yet right?
…eedback - Move wt/db CLI files into tools/worktree-db/ subfolder to reduce top-level clutter (reviewer feedback from josip) - Fix generate-db-types.sh to write to temp file before mv (prevents types file truncation on failure) - Move readState() inside lock acquisition for db fork and wt setup to prevent stale-state race conditions - Add input validation guard in postgres.ts databaseExists() and terminateConnections() - Add try/catch around JSON.parse in readState() with helpful error - Remove dead exports: getDbPort(), getMainPort() - Deduplicate git worktree list --porcelain call in wt list - Remove checkDbBranchAlignment() from app/server.ts (wrong layer) - Keep PORT env var reading in app/server.ts - Add .trees/ to .gitignore - Add implementation notes section to plan doc - Update devenv.nix paths for restructured tools - Use bunx for supabase CLI in hook script (not on system PATH)
Worktrees need the full .env (secrets, API keys), not just a PORT override. Copy the root .env and replace the PORT line. Also add dotenv/config import to server.ts for .env loading.
Summary
wtCLI for managing git worktrees with per-branch Supabase databasesdbCLI for database branching — fork, switch, list, delete, link, status