neon-postgres-branches

작성자: neondatabase

이 스킬의 결과는 생성된 Neon 브랜치(또는 생성이 진행될 수 없는 경우 명확하고 실행 가능한 다음 단계)여야 합니다. 올바른 브랜치 유형을 선택한 다음 MCP 또는 CLI를 통해 브랜치 생성을 실행합니다.

npx skills add https://github.com/neondatabase/agent-skills --skill neon-postgres-branches

Neon Postgres Branching

The outcome of this skill should be a created Neon branch (or a clear, actionable next step if creation cannot proceed). Choose the correct branch type, then execute branch creation via MCP or CLI.

  • Normal branch for realistic migration and query testing with real data.
  • Schema-only branch (Beta) for sensitive data workflows where structure is needed without copying rows.

Branch Type Decision

Use this decision rule first:

  1. If the user wants to test complex migrations, performance, or behavior against production-like data, choose a normal branch.
  2. If the user needs to avoid copying sensitive data, choose a schema-only branch.

If the request is ambiguous, ask one clarifying question: "Do you need realistic data for testing, or only schema structure because the data is sensitive?"

Tool Selection: CLI or MCP

Always support both Neon CLI and Neon MCP server. Prefer the tool the user already has installed and authenticated.

MCP link: https://neon.com/docs/ai/neon-mcp-server.md CLI link: https://neon.com/docs/reference/cli-quickstart

Selection order

  1. Check MCP first in MCP-enabled environments:
    • If Neon MCP tools are available and authenticated (for example, listing projects works), use MCP.
  2. If MCP is unavailable or not authenticated, check CLI:
    • Run neon --version to confirm CLI is installed.
    • Run neon projects list to confirm auth/context.
  3. If CLI is missing, direct installation via quickstart.
  4. If CLI is installed but not authenticated, guide the user through neon auth (or API key auth), then continue.
  5. If both MCP and CLI paths are unsuccessful, use the Neon REST API:

MCP branch flow

  1. Choose normal vs schema-only based on data sensitivity and migration-testing goals.
  2. Use branch tools (for example, create_branch) to create the branch.
  3. Validate with read tools (for example, describe_branch).
  4. For migration workflows, prefer branch-based migration flows before applying to main.

Create a Normal Branch (Preferred for Real-Data Migration Testing)

Use this when the user needs realistic testing conditions. Real production-like data can expose edge cases your seed or data migration scripts miss, which helps catch migration issues before going live.

Link: https://neon.com/docs/introduction/branching.md

Steps

  1. Use MCP if already available/authenticated; otherwise verify CLI with neon --version.
  2. Ensure project context is set (neon set-context --project-id <your-project-id>) or include --project-id on commands.
  3. Create branch:
neon branches create \
  --name <branch-name> \
  --parent <parent-branch-id-or-name> \
  --expires-at 2026-12-15T18:02:16Z
  1. Optionally fetch a connection string for the new branch:
neon connection-string <branch-name>

Create a Schema-Only Branch (Beta, Sensitive Data)

Use this when users must not copy production rows into the test branch.

Link: https://neon.com/docs/guides/branching-schema-only.md

Steps

  1. Use MCP if already available/authenticated; otherwise verify CLI with neon --version.
  2. Create schema-only branch:
neon branches create \
  --name <schema-only-branch-name> \
  --parent <parent-branch-id-or-name> \
  --schema-only \
  --expires-at 2026-12-15T18:02:16Z

If multiple projects exist, include:

neon branches create \
  --name <schema-only-branch-name> \
  --parent <parent-branch-id-or-name> \
  --schema-only \
  --project-id <your-project-id> \
  --expires-at 2026-12-15T18:02:16Z

Beta Support Guidance (Mandatory)

Schema-only branching is in Beta. If users report unexpected behavior, errors, or missing capabilities:

  1. Ask them to share feedback in the Neon Console:
  2. Recommend opening a support conversation in the Neon Discord:

Reset from parent

Use this when a child branch has drifted and the user wants a clean refresh from the parent branch's latest schema and data.

Link: https://neon.com/docs/guides/reset-from-parent.md

What it does

  • Fully replaces the child branch schema and data with the parent's latest state.
  • Does not merge; local changes on the child branch are lost.
  • Keeps the same connection details, but active connections are briefly interrupted during reset.

When to recommend it

  • Development or staging branch is too far behind production.
  • User wants to start a new feature from a clean parent-aligned state.
  • Team wants to refresh staging from production for consistent testing baselines.

Hard constraints and blockers

  • Only child branches can be reset (root branches and schema-only root branches cannot be reset from parent).
  • If the target branch has children, reset is blocked until those child branches are removed.
  • After a parent branch is restored from snapshot, reset-from-parent may be unavailable for up to 24 hours.
  • Reset-from-parent always uses the current parent state; use Instant restore for point-in-time recovery needs.

CLI usage

neon branches reset <id|name> --parent --preserve-under-name <backup-branch-name>

If project context is not already set, include project ID:

neon branches reset <id|name> --parent --preserve-under-name <backup-branch-name> --project-id <project-id>

--preserve-under-name keeps the pre-reset state as a backup branch for rollback, but adds one extra branch to clean up later.

Optional context setup to avoid repeating --project-id:

neon set-context --project-id <project-id>

Console and API usage

  • Console: Open the target child branch, then select Reset from parent from Actions.
  • API: Use the restore endpoint for the branch and set source_branch_id to the parent branch ID.

Notes and Caveats

  • Schema-only branches are for structure-only cloning and sensitive/compliant data controls.
  • Schema-only branches are independent root branches (no parent branch and no shared history), so reset-from-parent does not apply.
  • For migration testing that depends on real-world row shapes, volumes, and edge cases, prefer normal branches.
  • Root branch allowances and per-branch storage limits can cap how many schema-only branches users can create.
  • If a user is unsure, default recommendation is:
    • Normal branch for migration validation.
    • Schema-only branch for compliance and privacy constraints.

Useful Workflow Patterns

If the user asks for process recommendations (not just a single command), suggest these:

  • One branch per PR: Create branch when PR opens, delete when merged/closed, keep migration tests isolated.
  • One branch per test run: Create branch at pipeline start, run migrations/tests, delete at end for deterministic CI.
  • One branch per developer: Isolated dev environments with production-like shape; avoid team collisions on shared test data.
  • PII-aware branching: If production has sensitive data, derive dev/PR branches from an anonymized branch or use schema-only branches.
  • Ephemeral lifecycle hygiene: Set branch expiration and automate cleanup so old branches do not accumulate avoidable storage/history cost.

Post-creation environment update prompt

After branch creation, ask whether the user wants to update local environment credentials to point at the new branch.

  • Ask: "Do you want me to update your .env DATABASE_URL to this new branch connection string?"
  • If yes, write the new branch connection string to the requested env file/key.
  • If no, leave credentials unchanged and share the connection string for manual use.
  • Never overwrite an existing env key without explicit confirmation.

Neon Infrastructure as Code (neon.ts)

Beyond creating branches imperatively (CLI / MCP / API above), you can program what configuration new branches receive declaratively in neon.ts — Neon's infrastructure-as-code file (see the neon skill for the full reference). The branch property is a function of the branch being evaluated that returns its settings, so every branch born from your project gets a consistent lifecycle and compute profile without per-branch flags.

npm i @neon/config
// neon.ts
import { defineConfig } from "@neon/config/v1";

export default defineConfig({
  branch: (branch) => {
    if (branch.exists) return {}; // never reconcile existing branches
    if (branch.isDefault) return { protected: true };
    if (branch.name.startsWith("preview/") || branch.name.startsWith("dev")) {
      return {
        parent: "main",
        ttl: "7d", // ephemeral: auto-expire 7 days after creation (max 30d)
        postgres: {
          computeSettings: {
            autoscalingLimitMinCu: 0.25, // scale to zero
            autoscalingLimitMaxCu: 1, // keep throwaway branches cheap
            suspendTimeout: "5m",
          },
        },
      };
    }
    return {};
  },
});

The closure receives a read-only descriptor of the target branch — name, exists, isDefault, parentId, and more — and returns the tuning to apply: parent, ttl (auto-expiry), protected, and postgres.computeSettings. This is the declarative complement to the Ephemeral lifecycle hygiene and per-PR / per-test patterns above: instead of remembering --expires-at on every neon branches create, the TTL and compute profile live in version control and apply to every matching branch.

Because neon checkout applies this policy when it creates a branch, a fresh preview/* or dev-* branch comes up already expiring and scaled-to-zero. Checking out an existing branch doesn't reconcile it — run neon deploy (alias for neon config apply) to apply changes to a branch that already exists.

Branching in CI/CD

Common CI/CD use cases for Neon branches:

  • Per-PR preview deployments: Branch on PR open, deploy the preview against it, delete on close. Each PR gets an isolated database branch. Injecting the branch's DATABASE_URL into the deployed app is hosting-provider-specific — see preview-branches-with-cloudflare, preview-branches-with-vercel, or preview-branches-with-fly for tested patterns.
  • Migration testing in CI: Run risky schema changes against a branch with production-like data before merge.
  • Schema diff visibility: Use the schema-diff GitHub Action to auto-comment a DB-layer diff on the PR.

Examples

Example 1: Migration testing with realistic data

User input: "I need to test a risky migration against production-like data."

Agent output shape:

  1. Recommend a normal branch and explain why.
  2. Share docs link: https://neon.com/docs/introduction/branching
  3. Check the available/authenticated tool path first (MCP, otherwise CLI with neon --version).
  4. Provide commands:
    • neon branches create --name migration-test --parent main --expires-at 2026-12-15T18:02:16Z
    • neon connection-string migration-test

Example 2: Sensitive data development workflow

User input: "We cannot copy production data because of compliance."

Agent output shape:

  1. Recommend schema-only branch and explain why.
  2. Share docs link: https://neon.com/docs/guides/branching-schema-only
  3. Check the available/authenticated tool path first (MCP, otherwise CLI with neon --version).
  4. Provide command:
    • neon branches create --name compliance-dev --parent main --schema-only --project-id <your-project-id> --expires-at 2026-12-15T18:02:16Z
  5. Mention Beta support path:

Further reading

neondatabase의 다른 스킬

claimable-postgres
neondatabase
로컬 개발, 데모, 프로토타이핑 및 테스트 환경을 위한 즉시 사용 가능한 Postgres 데이터베이스입니다. 계정이 필요하지 않습니다. 데이터베이스는 Neon 계정에 클레임되지 않으면 72시간 후에 만료됩니다.
official
neon-postgres-egress-optimizer
neondatabase
사용자가 Postgres 데이터베이스에서 과도한 데이터 전송(이그레스)을 유발하는 애플리케이션 측 쿼리 패턴을 진단하고 수정하도록 안내합니다. 대부분의 높은 이그레스 비용은 애플리케이션이 실제 사용하는 데이터보다 더 많은 데이터를 가져오기 때문에 발생합니다.
official
plugin-manager
neondatabase
이 저장소의 Cursor와 Claude Code 전반에 걸쳐 플러그인 구조와 구성을 관리합니다. 플러그인 폴더를 생성, 업데이트 또는 검토할 때 사용하세요…
official
skill-creator
neondatabase
효과적인 스킬을 생성하기 위한 가이드입니다. 이 스킬은 사용자가 Claude의 기능을 확장하는 새로운 스킬을 만들거나 기존 스킬을 업데이트하려 할 때 사용해야 합니다.
official
add-neon-docs
neondatabase
사용자가 Neon에 대한 문서 추가, 문서 추가, 참조 추가, 또는 문서 설치를 요청할 때 이 스킬을 사용하세요. Neon 모범 사례 참조 링크를 추가합니다…
official
neon-auth
neondatabase
애플리케이션에 Neon Auth를 설정합니다. 인증을 구성하고, 인증 라우트를 생성하며, UI 컴포넌트를 생성합니다. Next.js에 인증을 추가할 때 사용합니다.
official
neon-drizzle
neondatabase
완전한 기능을 갖춘 Drizzle ORM 설정을 프로비저닝된 Neon 데이터베이스와 함께 생성합니다. 종속성을 설치하고, 데이터베이스 자격 증명을 프로비저닝하며, 연결을 구성하고,…
official
neon-js
neondatabase
완전한 Neon JS SDK를 설정하여 통합 인증 및 PostgREST 스타일 데이터베이스 쿼리를 제공합니다. 인증 클라이언트, 데이터 클라이언트 및 타입 생성을 구성합니다. 다음 경우에 사용하세요…
official