Skip to main content

@effectstream/db-emulator

Package: @effectstream/db-emulator · Source

A standalone migration runner for EffectStream's database. Apply the EffectStream system schema plus your migrations to a Postgres or PgLite instance without booting the full runtime — handy for unit tests and CI fixtures.

Install

bun add @effectstream/db-emulator
# or
npm install @effectstream/db-emulator

This package exists separately from @effectstream/db to break the circular dependency between @effectstream/db and @effectstream/sm — both of which standAloneApplyMigrations needs.

Standalone usage

import { getConnection } from "@effectstream/db";
import { standAloneApplyMigrations } from "@effectstream/db-emulator";
import { localhostConfig } from "./config.ts";
import { migrationTable } from "./migrations.ts";

const db = await getConnection();
await standAloneApplyMigrations(
db,
migrationTable,
localhostConfig,
/* userDefinedPrimitives */ undefined,
);

You're left with a database that has every EffectStream system table plus your migrations applied, ready for tests to read and write directly against the client returned by getConnection().

Use only against ephemeral / in-memory databases. The function assumes it owns the schema.

Inside EffectStream

Designed for use in tests and migration tooling. Pair with @effectstream/db/start-pglite for a quick in-memory database that's ready for app code to read / write.

Key exports

  • standAloneApplyMigrations(db, migrationTable, config, userPrimitives?) — apply the EffectStream system migrations plus your own, against the given pg client.

Examples

Runnable: test/examples.test.ts.

For the broader migration pattern, see templates/*/packages/client/database/sql-to-ts.ts.