PlanetScale
PlanetScale is a serverless database platform that supports both MySQL and PostgreSQL, providing horizontal scaling, branching workflows, and zero-downtime schema changes. Alchemy provides resources to manage PlanetScale databases, branches, and access controls programmatically.
Official PlanetScale Documentation | PlanetScale API Reference
Resources
Section titled “Resources”- Database - Create and manage PlanetScale MySQL and PostgreSQL databases with configuration options
- Branch - Create and manage database branches for development workflows
- Password - Create and manage database passwords with specific roles and permissions (MySQL only)
- Role - Create and manage database roles with inherited permissions (PostgreSQL only)
MySQL Example
Section titled “MySQL Example”import { Database, Branch, Password } from "alchemy/planetscale";
// Create a MySQL databaseconst database = await Database("my-app-db", { name: "my-app-db", organizationId: "my-org", clusterSize: "PS_10", allowDataBranching: true, automaticMigrations: true,});
// Create a development branchconst devBranch = await Branch("feature-123", { name: "feature-123", organizationId: "my-org", databaseName: database.name, parentBranch: "main", isProduction: false,});
// Create passwords for database access (MySQL only)const readerPassword = await Password("app-reader", { name: "app-reader", organizationId: "my-org", databaseName: database.name, branchName: "main", role: "reader"});
const writerPassword = await Password("app-writer", { name: "app-writer", organizationId: "my-org", databaseName: database.name, branchName: devBranch.name, role: "writer", ttl: 86400 // 24 hours});PostgreSQL Example
Section titled “PostgreSQL Example”import { Database, Branch, Role } from "alchemy/planetscale";
// Create a PostgreSQL databaseconst pgDatabase = await Database("my-pg-db", { name: "my-pg-db", organizationId: "my-org", clusterSize: "PS_10", kind: "postgresql", allowDataBranching: true, automaticMigrations: true,});
// Create a development branchconst devBranch = await Branch("dev-branch", { name: "development", organizationId: "my-org", database: pgDatabase, parentBranch: "main", isProduction: false,});
// Create roles for database access (PostgreSQL only)const readerRole = await Role("app-reader", { database: pgDatabase, branch: pgDatabase.defaultBranch, inheritedRoles: ["pg_read_all_data", "pg_read_all_settings"],});
const adminRole = await Role("app-admin", { database: pgDatabase, branch: devBranch, inheritedRoles: ["postgres"], ttl: 3600, // 1 hour});