Skip to content

test(sim): run on an in-memory PGlite when DATABASE_URL is unset - #115

Closed
kyscott18 wants to merge 1 commit into
test/sim-db-transportfrom
test/sim-pglite
Closed

kyscott18 wants to merge 1 commit into
test/sim-db-transportfrom
test/sim-pglite

Conversation

@kyscott18

@kyscott18 kyscott18 commented Nov 2, 2026 •

Copy link
Copy Markdown
Collaborator

Last of four stacked PRs, on #114: PGlite transport → sim DB as a transport with injected errors → PGlite for the sim. (#112 is merged.)

  • DATABASE_URL unset: the run uses { kind: "pglite" } (feat(typewriter): add an in-memory PGlite database transport #113's in-memory transport) and needs no Postgres. Nothing is left behind after a run.
  • DATABASE_URL set: the run creates a Postgres database of its own on that server, as before. It's dropped on a pass and kept, with its psql command, on a failure. This keeps the production Bun SQL driver covered, and gives a database to inspect when a seed fails: rerun it with DATABASE_URL.
  • makeDbTransport(options) picks the transport from DatabaseOptions, for makeDb and the sim.

Bun loads .env from the working directory, so a packages/typewriter/.env copied from .env.example sets DATABASE_URL and selects Postgres.

BOM. PGlite reads a text value that starts with U+FEFF without it (see #113). The sim stores no strings since #111, so it is unaffected.

Speed. PGlite isn't faster per run. Measured on 0x01 before the split:

  • Cold PGlite.create() (WASM initdb) takes ~770 ms, against 38 ms for CREATE DATABASE.
  • PGlite's queries run on the sim's own thread, about 0.3 ms more per database call.
  • The database is 12–17 % of a run; Anvil RPCs and the runtime dominate.
  • A cached initdb snapshot (loadDataDir, ~185 ms in a fresh process) would remove most of the startup gap if PGlite sweeps become common.

Checked, sequentially:

🤖 Generated with Claude Code

With `DATABASE_URL` set, the run creates a Postgres database of its own on
that server, as before; without it, the run uses `{ kind: "pglite" }` and
needs no Postgres. `makeDbTransport` picks the transport from
`DatabaseOptions`, for `makeDb` and the simulation.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant