Skip to content

fix: default db:generate to PGlite so Postgres is not required - #49

Open
adsqx wants to merge 1 commit into
seveibar:mainfrom
adsqx:fix/default-generate-pglite
Open

fix: default db:generate to PGlite so Postgres is not required#49
adsqx wants to merge 1 commit into
seveibar:mainfrom
adsqx:fix/default-generate-pglite

Conversation

@adsqx

@adsqx adsqx commented Aug 20, 2026

Copy link
Copy Markdown

@algora-pbc /claim #2

Fixes #2db:generate no longer needs a Postgres server running.

generate already had a working PGlite path, it was just off by default. This PR flips the default instead of adding new machinery:

  • src/cli.ts: --pglite now defaults to true, so yargs gives you --no-pglite as the escape hatch for generating against a real database. The handler now awaits generate(), which it previously did not — without that the CLI could exit before generation finished.
  • src/generate.ts: pglite defaults to true so programmatic generate(ctx) behaves like the CLI, and the PGlite TCP server is closed (and DATABASE_URL restored) in a finally block so a failed generation cannot leak a listening socket.
  • src/init.ts: scaffolds pgstrap generate --pglite — explicit intent in new projects even though the CLI default already covers it.
  • README: one line saying npm run db:generate uses in-memory PGlite and needs no Postgres, plus --no-pglite for an existing database.
  • Tests: init.test.ts updated; a short test in the existing generate.pglite.test.ts asserts the default path generates types with no server running.

Why this over the other open PRs: changing only the init script leaves every already-initialized project still running pgstrap generate against a Postgres that isn't there, so the issue isn't actually fixed for them. Adding a separate db:generate:postgres script invents surface the issue didn't ask for, and the larger rewrites (env sniffing, restructured generate.ts, lockfile churn) change far more than the bug requires. This is 5 files, no new dependencies, no reformatting noise. bun test and bun run format:check are green.

Flip --pglite default to true (with --no-pglite escape hatch), await
the generate CLI handler, close the in-memory server in finally, and
scaffold the init script with --pglite.
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