Skip to content

feat: make pglite default for generate without requiring external postgres - #64

Open
iprasen wants to merge 1 commit into
seveibar:mainfrom
iprasen:feat/pglite-generate-default-2
Open

feat: make pglite default for generate without requiring external postgres#64
iprasen wants to merge 1 commit into
seveibar:mainfrom
iprasen:feat/pglite-generate-default-2

Conversation

@iprasen

@iprasen iprasen commented Sep 10, 2026

Copy link
Copy Markdown

Overview

Fixes #2.

Claims Algora bounty:
@algora-pbc /claim #2

Problem

Previously, running bun run db:generate or pgstrap generate defaulted to connecting to an external PostgreSQL instance unless --pglite was explicitly supplied. When running in environments without PostgreSQL running in the background, type generation failed.

Solution

  1. Default pglite to true in generate():
    • generate() now defaults to pglite = true, running migrations in a temporary in-memory PGlite instance and dumping structure without requiring external PostgreSQL.
  2. Default CLI option pglite to true:
    • Running pgstrap generate (and thus bun run db:generate) works immediately out of the box.
    • External Postgres users can opt out via pgstrap generate --no-pglite.
  3. Lifecycle & Environment Variable Cleanup:
    • Wrapped PGlite socket server generation in a try ... finally block so that server.close(), PGlite disposal, and process.env.DATABASE_URL restoration always run even if type generation or tree dumping fails.
  4. CLI Handler Async Safety:
    • await generate(...) in the CLI action handler to ensure errors are propagated and asynchronous execution finishes before exiting.
    • Added ESM/CJS compatibility for the CLI invocation.
  5. Testing:
    • Added unit and integration tests for:
      • generate defaulting to PGlite when the option is omitted.
      • generate opting out to external Postgres when pglite: false.
      • DATABASE_URL restoration and socket server cleanup when errors occur.

- Default generate() to use pglite: true
- Default CLI generate command option pglite to true with --no-pglite opt-out
- Ensure socket server, PGlite instance, and DATABASE_URL cleanup in try...finally
- Await generate() in CLI handler to properly propagate async execution
- Add comprehensive tests for default pglite execution, opt-out, and cleanup
@iprasen

iprasen commented Sep 10, 2026

Copy link
Copy Markdown
Author

@algora-pbc /claim #2

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