Database
The Database resource lets you create and manage PlanetScale databases with comprehensive configuration options for scaling, migrations, and security. PlanetScale supports both MySQL and PostgreSQL databases.
Minimal Example
Section titled “Minimal Example”Create a basic MySQL database with default settings:
import { Database } from "alchemy/planetscale";
const database = await Database("my-app-db", { name: "my-app-db", organizationId: "my-org", clusterSize: "PS_10",});PostgreSQL Database
Section titled “PostgreSQL Database”Create a PostgreSQL database:
import { Database } from "alchemy/planetscale";
const pgDatabase = await Database("my-pg-db", { name: "my-pg-db", organizationId: "my-org", clusterSize: "PS_10", kind: "postgresql",});Database with Regional Configuration
Section titled “Database with Regional Configuration”Create a database in a specific region with custom settings:
import { Database } from "alchemy/planetscale";
const database = await Database("eu-app-db", { name: "eu-app-db", organizationId: "my-org", region: { slug: "eu-west", }, clusterSize: "PS_20", allowDataBranching: true, automaticMigrations: true, requireApprovalForDeploy: true,});Production Database with Advanced Features
Section titled “Production Database with Advanced Features”Create a production database with comprehensive configuration:
import { Database } from "alchemy/planetscale";
const prodDatabase = await Database("production-db", { name: "production-db", organizationId: "my-org", region: { slug: "us-east", }, clusterSize: "PS_40", defaultBranch: "production", allowDataBranching: true, automaticMigrations: false, requireApprovalForDeploy: true, restrictBranchRegion: true, insightsRawQueries: true, productionBranchWebConsole: false, migrationFramework: "rails", migrationTableName: "schema_migrations",});Database with Custom API Key
Section titled “Database with Custom API Key”Create a database using a specific API key:
import { Database } from "alchemy/planetscale";
const database = await Database("custom-auth-db", { name: "custom-auth-db", organizationId: "my-org", clusterSize: "PS_10", apiKey: alchemy.secret(process.env.CUSTOM_PLANETSCALE_TOKEN),});PostgreSQL with ARM Architecture
Section titled “PostgreSQL with ARM Architecture”Create a PostgreSQL database with ARM architecture:
import { Database } from "alchemy/planetscale";
const armDatabase = await Database("arm-pg-db", { name: "arm-pg-db", organizationId: "my-org", clusterSize: "PS_10", kind: "postgresql", arch: "arm",});Adopting Existing Database
Section titled “Adopting Existing Database”Adopt an existing PlanetScale database for management:
import { Database } from "alchemy/planetscale";
const existingDatabase = await Database("existing-db", { name: "existing-db", organizationId: "my-org", clusterSize: "PS_20", adopt: true, allowDataBranching: false, automaticMigrations: true,});