Using BranchBase with Prisma ORM
This guide demonstrates how to use BranchBase with Prisma ORM (TypeScript / Node.js) for instant, conflict-free local database branching.
Problem: Prisma Migration Conflicts in Git
When collaborating on full-stack apps with Prisma, switching branches often breaks local development:
1. You run npx prisma migrate dev on feature/stripe-billing, adding new tables and non-nullable columns.
2. An urgent bug comes in on main -> you run git checkout main.
3. Starting your backend server crashes with:
PrismaClientKnownRequestError: The column `users.stripe_customer_id` does not exist in the current database.
npx prisma migrate reset) wipes all your mock seeds and test logins.
Solution: BranchBase + Prisma
BranchBase transparently routes Prisma queries to an isolated, copy-on-write clone of your development database whenever you switch Git branches. Your application's DATABASE_URL never changes.
Step-by-Step Setup
1. Initialize BranchBase in your Prisma Project
In your project repository:
This generates.branchbase.json and installs automated Git hooks in .git/hooks/.
2. Configure your .env and schema.prisma
Point Prisma to the BranchBase transparent proxy (default port: 5432):
Configure your prisma/schema.prisma datasource:
Warning: Do not configure a
directUrlpointing directly to backend container port5433. WhendirectUrlis configured, Prisma directs migrations to the underlying container directly, bypassing BranchBase and mutating the base database. Keep both runtime queries and migrations pointing to the BranchBase proxy port5432.
3. Start the BranchBase Proxy
Daily Git Workflow
1. Create and work on a feature branch
BranchBase's Git hook instantly snapshots yourmyapp_dev database into myapp_dev_feature_stripe_billing.
2. Run Prisma migrations freely
Your migrations apply solely to the isolatedmyapp_dev_feature_stripe_billing database.
3. Switch back to main anytime
BranchBase immediately routes all Prisma queries back to your clean myapp_dev database. Zero schema mismatch errors!
4. Check active branch database status
Output:🌿 BranchBase Status
• Active Git Branch: main
• Sanitized Name: main
• Target Database: myapp_dev
• Driver: postgres
• Proxy Port: 5432 -> Backend: 127.0.0.1:5433
• Git Hooks: ✅ Active (.git/hooks/post-checkout)
Best Practices
- Client Generation: Run
npx prisma generateafter branch switches if schema types changed. - Pruning Merged Databases: After your pull request is merged into
main, clean up disk space with: