Planetscale.Postgres reference
PostgresBranch
Section titled “PostgresBranch”Source:
src/Planetscale/Postgres/PostgresBranch.ts
A PlanetScale branch of a PostgresDatabase. For MySQL branches
use MySQLBranch instead.
PostgresBranch: Creating a Branch
Section titled “PostgresBranch: Creating a Branch”Branch from main
const branch = yield* Planetscale.PostgresBranch("Feature123", { database: "my-db", parentBranch: "main",});Branch from a PostgresDatabase resource
const db = yield* Planetscale.PostgresDatabase("MyDb", { clusterSize: "PS_10" });const branch = yield* Planetscale.PostgresBranch("Feature456", { database: db, parentBranch: "main",});PostgresBranch: Migrations and seed data
Section titled “PostgresBranch: Migrations and seed data”const branch = yield* Planetscale.PostgresBranch("Feature123", { database: db, parentBranch: "main", migrationsDir: "./migrations", importFiles: ["./seed.sql"],});PostgresDatabase
Section titled “PostgresDatabase”Source:
src/Planetscale/Postgres/PostgresDatabase.ts
A PostgreSQL PlanetScale database. For MySQL, use MySQLDatabase
instead.
PostgresDatabase: Creating a PostgreSQL Database
Section titled “PostgresDatabase: Creating a PostgreSQL Database”Basic PostgreSQL database
const db = yield* Planetscale.PostgresDatabase("MyDb", { clusterSize: "PS_10",});PlanetScale Metal (NVMe)
const db = yield* Planetscale.PostgresDatabase("MyDb", { clusterSize: "M1_10_AWS_ARM_D_METAL_10", arch: "arm",});PostgresDatabase: Migrations and seed data
Section titled “PostgresDatabase: Migrations and seed data”const db = yield* Planetscale.PostgresDatabase("MyDb", { clusterSize: "PS_10", migrationsDir: "./migrations/postgres", importFiles: ["./seed/postgres.sql"],});PostgresDatabase: Adoption
Section titled “PostgresDatabase: Adoption”import { adopt } from "alchemy/AdoptPolicy";
const db = yield* Planetscale.PostgresDatabase("Existing", { name: "existing-db", clusterSize: "PS_10",}).pipe(adopt());PostgresDefaultRole
Section titled “PostgresDefaultRole”Source:
src/Planetscale/Postgres/PostgresDefaultRole.ts
The default PlanetScale PostgreSQL role for a database branch.
PostgresDefaultRole: Creating a Default Role
Section titled “PostgresDefaultRole: Creating a Default Role”const db = yield* Planetscale.PostgresDatabase("MyDb", { clusterSize: "PS_10",});const defaultRole = yield* Planetscale.PostgresDefaultRole("MainRole", { database: db, forceReset: true,});PostgresRole
Section titled “PostgresRole”Source:
src/Planetscale/Postgres/PostgresRole.ts
A PlanetScale role for accessing a PostgreSQL database branch.
For MySQL databases, use MySQLPassword instead.
PostgresRole: Creating a Role
Section titled “PostgresRole: Creating a Role”Postgres admin role
const admin = yield* Planetscale.PostgresRole("Admin", { database: "my-db", inheritedRoles: ["postgres"],});Read-only role
const reader = yield* Planetscale.PostgresRole("Reader", { database: "my-db", inheritedRoles: ["pg_read_all_data", "pg_read_all_settings"],});Role with TTL
const tempReader = yield* Planetscale.PostgresRole("TempReader", { database: "my-db", inheritedRoles: ["pg_read_all_data"], ttl: 3600,});