Skip to content

feat: use pglite by default so postgres isn't required for generate#45

Open
Tamish-25 wants to merge 1 commit into
seveibar:mainfrom
Tamish-25:feat/pglite-typegen-2
Open

feat: use pglite by default so postgres isn't required for generate#45
Tamish-25 wants to merge 1 commit into
seveibar:mainfrom
Tamish-25:feat/pglite-typegen-2

Conversation

@Tamish-25

Copy link
Copy Markdown

What

pgstrap generate (and the scaffolded db:generate) now runs against in-memory PGlite by default — no postgres server required. The existing PGlite path (from #7) was opt-in; this flips the default per #2:

  • --pglite defaults to true; --no-pglite opts back into connecting to real postgres via DATABASE_URL
  • PGlite path hardened with try/finally so the gateway server, PGlite instance, and DATABASE_URL are restored even when codegen fails (previously leaked on error)

Bugs fixed en route (both blocked running the CLI at all in some environments)

  • src/cli.ts used the yargs CJS singleton, which breaks under ESM semantics (bun); switched to the standard v17 yargs(hideBin(process.argv)) factory and awaited the handler
  • src/get-project-context.ts imported pgstrap.config.js by raw absolute path, which node's ESM loader rejects on Windows (ERR_UNSUPPORTED_ESM_URL_SCHEME); fixed with pathToFileURL

Verification (machine with no postgres running at all)

  • End-to-end via bun source and via built node dist/cli.cjs: scaffolded temp projects with a node-pg-migrate migration, cleared PG*/DATABASE_URL env → exit 0, correct zapatos/schema.d.ts and structure/**/table.sql output
  • New regression test tests/cli-generate-default.test.ts
  • bun test: 4 pass / 0 fail; bun run build succeeds

Closes #2

/claim #2

🤖 Generated with Claude Code

Fixes seveibar#2. `pgstrap generate` (and therefore the scaffolded
`bun run db:generate` script) now defaults to running migrations
against an in-memory PGlite database, so generating zapatos types
and structure dumps no longer requires a running Postgres server.
Use `--no-pglite` to connect to a real Postgres via DATABASE_URL
as before.

Also:
- await the generate handler and pass argv through yargs' factory
  invocation (hideBin) so the CLI runs under both the CJS build and
  direct ESM/bun execution
- wrap the PGlite generate path in try/finally so DATABASE_URL is
  restored and the gateway server + PGlite instance are closed even
  when generation fails
- load pgstrap.config.js via pathToFileURL so dynamic import works
  on Windows
- add an end-to-end test that runs `pgstrap generate` with no flags
  in a scaffolded project with no reachable Postgres

Co-Authored-By: Claude Fable 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.

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

1 participant