Strata · guides
How to do things with Strata.
Each guide is a file you can run, set in the theatre’s world. What it prints is what the installed package printed.
First steps.
The theatre’s tables are written as a sequence of two migrations, and the file prints what a database that has run neither is owed.
pnpm add @niscorp/strata zodnpx tsx first.mtsimport { defineSequence, planMigrations, prepare } from '@niscorp/strata';
const theatre = defineSequence({
id: 'theatre.app',
migrations: [
{
description: 'Shows',
steps: [{ kind: 'sql', sql: 'CREATE TABLE shows (id text PRIMARY KEY, title text NOT NULL)' }],
},
{
description: 'Season passes',
steps: [{ kind: 'sql', sql: 'CREATE TABLE passes (member_id text PRIMARY KEY, season text NOT NULL)' }],
},
],
});
const plan = planMigrations(await prepare([theatre]), []);
console.log(plan.pending.map((migration) => `${migration.ref} ${migration.description}`));[ 'theatre.app/1 Shows', 'theatre.app/2 Season passes' ]
Nothing was applied: this is the plan. migrate(pool, [theatre]) from @niscorp/strata/postgres applies it to a Postgres and records it in a ledger, so a second run applies nothing.
Then, one at a time.
Each is a file of its own and adds one thing. Read them in order, or go to the one you need.