Skip to content

Planetscale.Postgres reference

Source: src/Planetscale/Postgres/PostgresBranch.ts

A PlanetScale branch of a PostgresDatabase. For MySQL branches use MySQLBranch instead.

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",
});
const branch = yield* Planetscale.PostgresBranch("Feature123", {
database: db,
parentBranch: "main",
migrationsDir: "./migrations",
importFiles: ["./seed.sql"],
});

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"],
});
import { adopt } from "alchemy/AdoptPolicy";
const db = yield* Planetscale.PostgresDatabase("Existing", {
name: "existing-db",
clusterSize: "PS_10",
}).pipe(adopt());

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,
});

Source: src/Planetscale/Postgres/PostgresRole.ts

A PlanetScale role for accessing a PostgreSQL database branch.

For MySQL databases, use MySQLPassword instead.

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,
});