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.
Minimal Example
Section titled “Minimal Example”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,});
Deletion
Section titled “Deletion”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,});
Production Branch with Cluster Size
Section titled “Production Branch with Cluster Size”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",});
Branch from Another Branch Object
Section titled “Branch from Another Branch Object”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,});
Branch from Backup
Section titled “Branch from Backup”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",});
Branch with Safe Migrations
Section titled “Branch with Safe Migrations”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,});
Adopting Existing Branch
Section titled “Adopting Existing Branch”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,});
Branch with Seed Data
Section titled “Branch with Seed Data”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",});