db-safety
DB Safety
Section titled “DB Safety”The Contract
Section titled “The Contract”Production DB → main branch only → never in any worktree .envStaging DB → persistent preview branch → long-lived worktrees onlyPreview DB → ephemeral Neon/Supabase branch → per PR worktreeDev DB → local or Neon dev branch → developer's personal worktreeConstraints
Section titled “Constraints”- Never put production
DATABASE_URLin any worktree.env— production credentials belong only to the main branch deployment (Vercel production, Railway production, etc.) - Each worktree gets its own database branch — use Neon
dev/<branch-name>or Supabase preview branch. Never share a DB across worktrees. - Warn on missing
.env— when a worktree is created for DB-touching work and no.envexists in the worktree, warn the developer to configureDATABASE_URLbefore running migrations - Migration PRs should be separate — when possible, merge migration-only PRs before app code PRs that depend on the new schema. This prevents coupled failures.
- No manual SQL on production — every schema change is a tracked migration file. Forward-only in production.
Per-Worktree .env Template
Section titled “Per-Worktree .env Template”When setting up a worktree that touches the database:
# .env in worktree root (gitignored)DATABASE_URL=<neon-branch-url-or-supabase-preview-url>DATABASE_URL_UNPOOLED=<direct-connection-for-migrations>For Neon: neonctl connection-string --branch dev/<branch-name> --pooled
For Supabase: get credentials from supabase branches get <branch-name>
For local: postgresql://postgres:postgres@localhost:54322/postgres
When Active
Section titled “When Active”- When creating worktrees for work that involves database schemas, migrations, or seed data
- When writing
.envfiles in any worktree - When safe-merge encounters migration files in a branch diff
- When writing-plans creates tasks involving DB schema changes
When Inactive
Section titled “When Inactive”- Projects with no database (pure frontend, CLI tools, static sites)
- Main branch deployments (production DB config is managed by the deploy platform)
Integration
Section titled “Integration”| Skill | How it uses this rule |
|---|---|
worktree | Warn when worktree has no .env and branch touches DB files |
safe-merge | Check for migration conflicts before merging |
writing-plans | Flag migration-first pattern when plan involves schema changes |
neon | Provides branching patterns for per-worktree DB isolation |
supabase | Provides branching patterns for per-worktree DB isolation |