Skip to content

fix: fall back to pglite for type generation#43

Open
sclee980528-prog wants to merge 1 commit into
seveibar:mainfrom
sclee980528-prog:fix/issue-2-pglite
Open

fix: fall back to pglite for type generation#43
sclee980528-prog wants to merge 1 commit into
seveibar:mainfrom
sclee980528-prog:fix/issue-2-pglite

Conversation

@sclee980528-prog

Copy link
Copy Markdown

Problem

pgstrap generate still required a reachable Postgres server unless users remembered to pass --pglite. That means the default bun run db:generate script scaffolded by pgstrap could fail on a machine without local Postgres running.

Approach

  • Make generate default to an auto mode: use the configured Postgres database when it is reachable, and fall back to PGlite only when the connection is unavailable.
  • Keep both explicit paths:
    • pgstrap generate --pglite forces the embedded PGlite flow.
    • pgstrap generate --no-pglite requires real Postgres and disables fallback.
  • Reuse the existing PGlite plus pg-gateway wire-protocol bridge so Zapatos and pg-schema-dump can introspect through normal Postgres clients.
  • Restore DATABASE_URL and close the temporary bridge server, sockets, and PGlite instance after generation.
  • Add regression coverage for default generation when Postgres is unavailable.

Verification

  • npm_config_cache=/private/tmp/bounty-pgstrap-npm npx --yes bun@1.2.21 test
    • 4 pass, 0 fail
  • npm_config_cache=/private/tmp/bounty-pgstrap-npm npx --yes bun@1.2.21 run format:check
    • passed
  • npm_config_cache=/private/tmp/bounty-pgstrap-npm npx --yes bun@1.2.21 run build
    • passed, including DTS build
  • git diff --check
    • passed
  • Confirmed no postgres or postmaster process was running with pgrep -fl 'postgres|postmaster'.
  • Created a fixture project and ran bun run db:generate with DATABASE_URL and PG* env vars unset.
    • It printed Postgres unavailable; generating with PGlite.
    • It generated src/db/zapatos/schema.d.ts.
    • It generated src/db/structure/public/tables/widgets/table.sql.
  • Compared auto-fallback output against explicit --pglite output for the same fixture.
    • Zapatos diff: 0
    • Structure diff: 0

Usage

Default behavior now works without local Postgres:

bun run db:generate

Force PGlite:

pgstrap generate --pglite

Require real Postgres:

pgstrap generate --no-pglite

@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.

1 participant