---
title: "A Postgres branch for every pull request | Xata"
description: "Give every pull request its own Postgres branch with production-shaped data. Run the migration in review, not in production. Created when the PR opens, deleted when it closes."
source: "https://xata.io/solutions/pull-request"
---

# Test every migration before it merges

Every pull request gets its own Postgres branch, copied from production or staging. It is created when the pull request opens and deleted when it closes.

[Read the docs](/docs/automations/github-app)[Get started](https://console.xata.io/signup)

### Copy-on-write

A branch starts from its parent’s data without copying it.

### Its own connection string

Each pull request gets an isolated Postgres database.

### Deleted on close

The branch goes away when the pull request merges or closes.

The problem

## Schema changes are the ones nobody wants to merge blind

Most teams review migrations against a shared staging database that does not look like production.

- One staging database, shared by the whole team
- Access limited to a few people
- Stale data and seed scripts that no longer match production
- Two pull requests that change the schema collide
- A real copy of the data means a dump and restore nobody has time for

## A branch copies no data

The branch reads its parent’s data and keeps only what the pull request changes, so it is ready in about three seconds with the full schema and rows.

1. 01

   ### Pull request opens

   A developer or a coding agent opens a pull request.

2. 02

   ### A database branch is created

   The Xata GitHub App creates a branch from the root branch you picked, staging if you have one and production otherwise, and comments the branch name on the pull request.

3. 03

   ### Review against real data

   Run the migration on the branch with xata roll migrate and point the app at it. Reviewers see the change against the real schema and real rows.

4. 04

   ### The branch is deleted on close

   When the pull request merges or closes, the GitHub App deletes the branch. Nothing is left running.

Under the hood

### How copy-on-write branching works

Xata separates Postgres compute from copy-on-write storage.

[See the architecture](/postgres-branching#storage-architecture)

Set it up

## Two ways to set it up

Automatic

### GitHub App or GitHub Actions

- GitHub App
- GitHub Actions

1. 01Link the repository to a Xata project once
2. 02Every pull request gets a branch, with no API key stored in GitHub
3. 03Need custom branch names, seed data or a merge check? Use the Actions workflows

- [GitHub App](/docs/automations/github-app)
- [Branch per pull request](/docs/automations/ga-pr)
- [Merge readiness check](/docs/automations/ga-check)
- [Cleanup workflow](/docs/automations/ga-cleanup)

Agent-driven

### Let your coding agent do it

- Claude Code
- Cursor
- Codex

1. 01The agent creates the branch and runs the migration against it
2. 02It checks the result
3. 03It opens the pull request, with a working database behind it

Under the hood

- [Xata for coding agents](/docs/ai-agents/overview)
- [Agent guides](/docs/ai-agents/claude-code)

Coding agents

## Your agent can run the whole workflow

Connect the Xata MCP server or install the CLI, and your coding agent can create branches, apply migrations and read schema without touching production.

- Claude Code
- Cursor
- Codex
- VS Code (Copilot)
- Windsurf
- Cline
- OpenCode
- Zed

### [Xata for coding agents](/docs/ai-agents/overview)

[CLI, MCP and agent skills in one place.](/docs/ai-agents/overview)

[Read the guide](/docs/ai-agents/overview)

### [MCP server](/docs/platform/mcp)

[Setup for every supported client.](/docs/platform/mcp)

[Connect MCP](/docs/platform/mcp)

Before and after the merge

## Real data in review, no downtime in production

### [Real data you are allowed to use](/postgres-data-masking)

[If production holds personal data, copy it into Xata with masking rules applied and branch pull requests from the masked copy.](/postgres-data-masking)

[Learn more](/postgres-data-masking)

### [Ship the migration without downtime](/postgres-schema-changes)

[Rehearse the migration on the branch, then apply it to production with pgroll, which serves the old and new schema side by side.](/postgres-schema-changes)

[Learn more](/postgres-schema-changes)

## More branching workflows

### [One branch per preview](/solutions/preview)

[A database for every Vercel and Netlify preview.](/solutions/preview)

[Learn more](/solutions/preview)

### [One branch per CI/CD](/solutions/ci-cd)

[A clean database for every test run.](/solutions/ci-cd)

[Learn more](/solutions/ci-cd)

### [Database Branching](/postgres-branching)

[How Xata branches Postgres.](/postgres-branching)

[Learn more](/postgres-branching)

## Give every pull request its own database

Run every migration on a branch with real data before it reaches production.

[Get started](https://console.xata.io/signup)[Talk to an engineer](https://cal.com/team/xata/xata-sales)
