Skip to main content

PlanetScale

PlanetScale is a serverless MySQL and PostgreSQL database platform built on Vitess.

Resources

Database

Create, manage and delete PlanetScale databases.
import { Database } from "alchemy/planetscale";

const db = await Database("my-app-db", {
  organization: "my-org",
  clusterSize: "PS_10"
});

Props

organization
string
default:"process.env.PLANETSCALE_ORGANIZATION"
The organization name where the database will be created
name
string
default:"${app}-${stage}-${id}"
The name of the database
clusterSize
PlanetScaleClusterSize
required
The database cluster size (e.g., PS_10, PS_20, PS_40, PS_80, PS_160, PS_320, PS_400)
kind
'mysql' | 'postgresql'
default:"mysql"
The engine kind for the database
region
object
The region where the database will be created
replicas
number
The number of replicas for the database. 0 for non-HA, 2+ for HA
adopt
boolean
Whether to adopt the database if it already exists in PlanetScale
delete
boolean
default:"true"
Whether to delete the database when the resource is destroyed. When false, the database will only be removed from the state but not deleted via API.
requireApprovalForDeploy
boolean
Whether or not deploy requests must be approved by a database administrator other than the request creator
restrictBranchRegion
boolean
Whether or not to limit branch creation to the same region as the one selected during database creation
insightsRawQueries
boolean
Whether or not full queries should be collected from the database
productionBranchWebConsole
boolean
Whether or not the web console can be used on the production branch of the database
defaultBranch
string
default:"main"
The default branch of the database
automaticMigrations
boolean
Whether or not to copy migration data to new branches and in deploy requests (MySQL only)
migrationFramework
string
A migration framework to use on the database (MySQL only)
migrationTableName
string
Name of table to use as migration table for the database (MySQL only)
allowDataBranching
boolean
Whether or not data branching is allowed on the database (MySQL only)
allowForeignKeyConstraints
boolean
Whether or not foreign key constraints are allowed on the database (MySQL only)
majorVersion
string
The PostgreSQL major version to use for the database (PostgreSQL only)
arch
'x86' | 'arm'
The CPU architecture for the database (PostgreSQL only)

Returns

id
string
The unique identifier of the database
name
string
The name of the database
state
string
The current state of the database
defaultBranch
string
The default branch name
plan
string
The plan type
createdAt
string
Time at which the database was created
updatedAt
string
Time at which the database was last updated
htmlUrl
string
HTML URL to access the database
organization
string
The organization of the database

Branch

Create or manage a PlanetScale database branch.
import { Branch } from "alchemy/planetscale";

const branch = await Branch("feature-123", {
  organization: "my-org",
  database: "my-database",
  parentBranch: "main",
  isProduction: false
});

Props

database
string | Database
required
The database name or Database object
organization
string
The organization name. Automatically inferred from the database if the database is provided as an object.
name
string
default:"${app}-${stage}-${id}"
The name of the branch
isProduction
boolean
required
Whether or not the branch should be set to a production branch or not
parentBranch
string | Branch
default:"main"
The parent branch name or Branch object
adopt
boolean
Whether to adopt an existing branch if it exists. If false and the branch exists, an error will be thrown. If true and the branch exists, it will be updated with the provided properties.
delete
boolean
default:"true"
Whether to delete the branch when the resource is destroyed. When false, the branch will only be removed from the state but not deleted via API.
backupId
string
If provided, restores the backup’s schema and data to the new branch. Must have restore_production_branch_backup(s) or restore_backup(s) access.
seedData
'last_successful_backup'
If provided, restores the last successful backup’s schema and data to the new branch. Must have restore_production_branch_backup(s) or restore_backup(s) access, in addition to Data Branching being enabled for the branch.
clusterSize
PlanetScaleClusterSize
The database cluster size is required if a backup_id is provided. If the branch is not a production branch, the cluster size MUST be “PS_DEV”.
safeMigrations
boolean
Enable or disable safe migrations on this branch

Returns

name
string
The name of the branch
parentBranch
string
The name of the parent branch
createdAt
string
Time at which the branch was created
updatedAt
string
Time at which the branch was last updated
htmlUrl
string
HTML URL to access the branch

Build docs developers (and LLMs) love