Skip to content

Default generate to PGlite so db:generate works without a running Postgres - #102

Open
metallicmonkey365 wants to merge 4 commits into
seveibar:mainfrom
metallicmonkey365:fix/generate-default-pglite
Open

metallicmonkey365 wants to merge 4 commits into
seveibar:mainfrom
metallicmonkey365:fix/generate-default-pglite

Conversation

@metallicmonkey365

Copy link
Copy Markdown

Closes #2

@algora-pbc /claim #2

Summary

bun run db:generate in a freshly scaffolded project no longer needs a Postgres server running in the background. Generation defaults to the existing PGlite path (added in #7) at every level:

  • src/generate.ts — generate() now defaults pglite to true. The temporary gateway server and PGlite instance are closed and DATABASE_URL is restored in a finally block, so a failed run no longer leaks the socket server or leaves the env override behind.
  • src/cli.ts — --pglite defaults to true (documented in --help); --no-pglite is the explicit opt-out for generating from an external Postgres via DATABASE_URL. The command now awaits generate().
  • src/init.ts — pgstrap init scaffolds db:generate as pgstrap generate --pglite and adds db:generate:postgres (pgstrap generate --no-pglite) so the opt-out is discoverable in scaffolded projects.
  • README.md — documents the new default and the opt-out.

Tests

New tests/generate.default-pglite.test.ts (the existing explicit---pglite test is untouched):

  • default generate() succeeds with DATABASE_URL pointing at an unreachable database — proving no external Postgres is involved — and restores the caller's DATABASE_URL
  • pglite: false really takes the external path (run in a subprocess: it fails with ECONNREFUSED against an unreachable DATABASE_URL instead of falling back to PGlite)
  • a failed generation still restores DATABASE_URL

Verification:

  • bun test — 6 pass, 0 fail
  • bun run build — success
  • bun run format:check — clean
  • End-to-end with the built CLI in a scratch project: pgstrap init scaffolds both scripts; pgstrap generate with an unreachable DATABASE_URL exits 0 and writes types + structure; pgstrap generate --no-pglite exits 1 with ECONNREFUSED

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.

Use pglite so that postgres isn't required when generating types

1 participant