Skip to content
GitHubXDiscordRSS

Branch

Learn how to create and manage PlanetScale database branches for development workflows and production scaling.

The Branch resource lets you create and manage PlanetScale database branches for development workflows, allowing you to safely develop schema changes in isolation.

Create a development branch from the main branch:

import { Branch } from "alchemy/planetscale";
const devBranch = await Branch("feature-123", {
name: "feature-123",
organization: "my-org",
database: "my-database",
parentBranch: "main",
isProduction: false,
});

By default, when a branch is deleted, the branch will be removed from the state but not deleted via API. This is to prevent accidental loss of data. This setting can be changed by setting the delete property to true.

import { Branch } from "alchemy/planetscale";
const devBranch = await Branch("feature-123", {
name: "feature-123",
organization: "my-org",
database: "my-database",
parentBranch: "main",
isProduction: false,
delete: true,
});

Create a production branch with specific cluster sizing:

import { Branch } from "alchemy/planetscale";
const prodBranch = await Branch("production", {
name: "production",
organization: "my-org",
database: "my-database",
parentBranch: "main",
isProduction: true,
clusterSize: "PS_20",
});

Create a branch using another Branch resource as the parent:

import { Branch } from "alchemy/planetscale";
const stagingBranch = await Branch("staging", {
name: "staging",
organization: "my-org",
database: "my-database",
parentBranch: "main",
isProduction: false,
});
const featureBranch = await Branch("feature-456", {
name: "feature-456",
organization: "my-org",
database: "my-database",
parentBranch: stagingBranch, // Using Branch object
isProduction: false,
});

Create a branch restored from a backup:

import { Branch } from "alchemy/planetscale";
const restoredBranch = await Branch("restored-data", {
name: "restored-data",
organization: "my-org",
database: "my-database",
parentBranch: "main",
isProduction: true,
backupId: "backup-123",
clusterSize: "PS_10",
});

Create a branch with safe migrations enabled:

import { Branch } from "alchemy/planetscale";
const safeBranch = await Branch("safe-migrations", {
name: "safe-migrations",
organization: "my-org",
database: "my-database",
parentBranch: "main",
isProduction: false,
safeMigrations: true,
});

Adopt and manage an existing branch:

import { Branch } from "alchemy/planetscale";
const existingBranch = await Branch("existing-feature", {
name: "existing-feature",
organization: "my-org",
database: "my-database",
parentBranch: "main",
isProduction: false,
adopt: true,
safeMigrations: false,
});

Create a branch with seeded data from the last successful backup:

import { Branch } from "alchemy/planetscale";
const seededBranch = await Branch("seeded-dev", {
name: "seeded-dev",
organization: "my-org",
database: "my-database",
parentBranch: "main",
isProduction: false,
seedData: "last_successful_backup",
});