Skip to content

Commit 047df86

Browse files
Brian Caselclaude
andcommitted
Isolate dev DB per git worktree
config/database.yml now derives the development DB name from the checkout's git state: the main checkout (.git is a directory) keeps using build_new_development, while git worktrees (.git is a pointer file) get build_new_development_<dirname>. Parallel Conductor worktrees, and apps forked from this template into a sibling checkout, no longer share or clobber each other's schemas. Override with DATABASE_NAME if needed. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent f2a365a commit 047df86

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

CLAUDE.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ Rails 8 + React 19 + PostgreSQL, bridged by **Inertia.js** (no separate API laye
1010

1111
Background jobs, caching, and WebSockets use the Rails 8 "Solid" trifecta (Solid Queue, Solid Cache, Solid Cable), all database-backed. **All four share the single PostgreSQL database** (`build_new_<env>` by default) — there are no separate cache/cable/queue databases, no `db/cache_schema.rb` / `db/cable_schema.rb` / `db/queue_schema.rb`, and `config/cache.yml` / `config/cable.yml` / `config/queue.yml` have no separate connection blocks. Override the connection via `DATABASE_URL` or the `DATABASE_USER` / `DATABASE_PASSWORD` / `DATABASE_HOST` / `DATABASE_PORT` env vars (see `config/database.yml`).
1212

13+
**Per-worktree dev DB isolation.** `config/database.yml` derives the development DB name from the checkout's git state. The main checkout (where `.git` is a directory) keeps using `build_new_development`. Each git worktree (where `.git` is a pointer file written by `git worktree add`, e.g. Conductor workspaces) gets its own DB suffixed with the worktree directory name — `build_new_development_<dirname>` — so parallel worktrees never share or clobber each other's schemas. This matters when forking this template into a new app: if two checkouts share a dev DB, migrations from one will land in the other and `db:schema:dump` will commit phantom tables. Override the derived name with `DATABASE_NAME` if needed.
14+
1315
## Commands
1416

1517
```bash

config/database.yml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,24 @@ default: &default
2020
host: <%= ENV.fetch("DATABASE_HOST") { "localhost" } %>
2121
port: <%= ENV.fetch("DATABASE_PORT") { 5432 } %>
2222

23+
<%
24+
# Per-worktree dev DB isolation. The main checkout (.git is a directory)
25+
# keeps using build_new_development; each git worktree (.git is a pointer
26+
# file written by `git worktree add`) gets its own DB suffixed with the
27+
# worktree directory name, so parallel Conductor worktrees never share or
28+
# clobber each other's schemas. Override with DATABASE_NAME to force a name.
29+
app_root = Dir.pwd
30+
worktree_db_suffix =
31+
if File.file?(File.join(app_root, ".git"))
32+
"_#{File.basename(app_root).gsub(/[^a-z0-9_]/i, "_").downcase}"
33+
else
34+
""
35+
end
36+
%>
37+
2338
development:
2439
<<: *default
25-
database: build_new_development
40+
database: <%= ENV.fetch("DATABASE_NAME") { "build_new_development#{worktree_db_suffix}" } %>
2641

2742
# Warning: The database defined as "test" will be erased and
2843
# re-generated from your development database when you run "rake".

0 commit comments

Comments
 (0)