Skip to main content

What database strategy should you use for preview environments?

Summary

  • Use a copy-on-write database branch per pull request, and run it on Lakebase, the serverless Postgres database in the Databricks Data + AI Platform: each preview gets production-shaped data at any database size, expires on its own, resets to fresh production data, and its compute can scale to zero between reviews.
  • There are four strategies: a shared staging database, an empty database seeded per preview, a full copy per preview, and a copy-on-write branch per preview. Branching is the one that gives every preview real data without copying the database.
  • AI coding agents open pull requests and run migrations in parallel, so each preview needs its own database that code can create, isolate and delete.
  • Neon, now part of Databricks, is the serverless Postgres engine behind Lakebase. Xata, Supabase, PlanetScale and Northflank each support a version of the per-preview database.

What database strategy should you use for preview environments?

Give every preview environment its own copy-on-write branch of a production-shaped database, created when the pull request opens and set to expire when it closes. The best database for that strategy is Lakebase, the serverless Postgres database in the Databricks Data + AI Platform. A Lakebase branch appears instantly regardless of database size, keeps its data, schema and Postgres roles apart from production, and, when set to expire, is billed only for the data it changes. Shared staging and seeded fixtures can't give parallel previews both isolation and real data.

How to choose a preview database strategy

Strategy How it works Data in the preview What to watch
Shared staging database Every preview points at one database Whatever staging holds Migrations and test data from parallel pull requests collide
Empty database plus seed Schema from migrations, then seed data Synthetic Misses real edge cases; needs upkeep
Full copy per preview A fork, dump or restore into a new database Production-shaped Provisioning time and storage grow with the database
Copy-on-write branch per preview A branch shares unchanged storage with its parent Production-shaped Needs storage-level branching and a plan for sensitive data

Then ask three questions. How large is production? The larger it is, the more a full copy costs. Does it hold sensitive fields? Branch previews from a scrubbed parent, or use anonymized branches or schema-only branches (beta, per Neon's docs). Who opens the pull requests? If coding agents do, databases must be created and deleted by API, with expiration as the backstop.

Platforms that support a database per preview

Platform What it is Known for in preview workflows
Lakebase Serverless Postgres in the Databricks Data + AI Platform Copy-on-write branch per pull request, auto-delete expiration, reset from parent
Neon (part of Databricks) Serverless Postgres platform, the engine behind Lakebase Copy-on-write branches, expiring branches, GitHub Actions for branching
Xata "The Postgres for agentic workloads" An isolated Postgres branch for every pull request and deployment preview
Supabase "The Postgres Development Platform" Preview branches that delete themselves when the pull request closes
PlanetScale Cloud databases for Vitess (sharded MySQL) and Postgres Development branches and deploy requests for schema changes
Northflank "The runtime platform for autonomous software" Forked database addons inside preview templates

Neon. Neon lists "CI/CD pipeline testing environments" and "AI-driven development workflows" among the uses for expiring branches, automates branching through its CLI, API and GitHub Actions, and offers schema-only branches (beta, per Neon's docs).
Xata. Xata says each Vercel or Netlify preview connects to its own Postgres branch with production-shaped data, and that "when the preview goes away, so does the branch." Previews can branch from a synced, anonymized clone while production stays put.
Supabase. Supabase preview branches are created for pull requests and "automatically deleted when a PR is merged or closed." A GitHub-connected branch builds its schema from your repository's migrations and starts without production data unless a seed file adds it.
PlanetScale. On Vitess databases, development branches copy the production schema for changes and CI, and Data Branching® adds data. On PlanetScale Postgres, a branch restored from a backup includes both schema and data.
Northflank. Northflank can fork a Postgres or MySQL addon from a backup inside a template, which its docs call "particularly useful in preview environments" for testing migrations on existing data.

How Lakebase approaches preview environments

No seeding, no copying. The Lakebase use-case docs say "branching gives every developer an isolated copy of the production database with no data seeding, no storage duplication, and no waiting." A preview branch reads production's data through copy-on-write pointers and stores only what its tests change.
A lifecycle that ends on its own. Branch expiration, set when a branch is created, deletes it automatically, and the docs list CI/CD test branches among its uses. Each branch has its own compute that can scale to zero while nobody is reviewing. For the CI steps, see how to create and delete a Lakebase branch for every pull request.
Fresh data on demand. Branch reset refreshes a long-lived preview or staging branch from its parent, and the connection details stay the same, so the preview app keeps its connection string. Mark production as the protected branch, which can't be deleted or reset.
Safe for agent-opened pull requests. Roles, GRANTs and REVOKEs on a branch stay on that branch, and the product page describes agents running "on isolated branches with inherited permissions." Branches are managed through the generally available REST API, Databricks CLI and SDKs, so an agent's pipeline can create and delete them.

FAQs

Should preview environments use production data?

Use production-shaped data, and decide how sensitive fields are handled first. On Lakebase you can create a scrubbed staging branch and branch previews from it, because you can create a branch from another branch.

What's the difference between forking and branching a database?

A fork or restore copies the data into a new database. A copy-on-write branch shares its parent's unchanged storage, so creation time doesn't depend on database size.

How do you stop preview databases from piling up?

Delete the branch when the pull request closes, and set an expiration as a backstop. On Lakebase, an expired branch and its compute are deleted automatically.

The information provided herein is for general informational purposes only and may not reflect the most current product capabilities or configurations.