Skip to content

Make initialized type generation work without external Postgres - #55

Open
gilmarGNJ wants to merge 1 commit into
seveibar:mainfrom
gilmarGNJ:fix/pglite-default-generation
Open

Make initialized type generation work without external Postgres#55
gilmarGNJ wants to merge 1 commit into
seveibar:mainfrom
gilmarGNJ:fix/pglite-default-generation

Conversation

@gilmarGNJ

Copy link
Copy Markdown

Closes #2.

@algora-pbc /claim #2

pgstrap generate and the API now use an in-memory PGlite database by default, so the existing script produced by pgstrap init needs no external Postgres. --no-pglite / pglite: false retain the external-database path.

The embedded path binds only to loopback, closes its gateway and PGlite instance, and restores both DATABASE_URL and POSTGRES_URI on success or failure. The latter matters because pg-schema-dump gives POSTGRES_URI precedence.

Testing the actual installed package uncovered two additional blockers in this exact workflow, addressed here with regressions:

  • Node on Windows requires a file URL when importing the project configuration; the test also includes spaces and # in its directory name.
  • A fresh installation resolves the unrestricted node-pg-migrate peer to v9, which exports a named runner. The loader now accepts that as well as the existing v6 default-export forms, without changing dependency versions.

Validation performed locally:

  • bun test: 14 passed, 0 failed, including real migrations, CLI/API defaults, the scaffolded script, the compiled Node CLI, export compatibility, error cleanup and environment restoration.
  • Build (CJS and DTS), bun run format:check, and git diff --check pass.
  • Built and packed the package locally (not published), installed it in a separate initialized fixture, and ran its unchanged bun run db:generate with external database URIs pointing at unused loopback port 1. It exits 0 and generates both typed Zapatos declarations and SQL for a migrated table with defaults and indexes. A repeat run produces the same type-file hash.
  • The installed-package check uses Node 22.17.1, Bun 1.4.0, node-pg-migrate 9.0.0 and PGlite 0.3.16; the source suite also exercises the repository-locked node-pg-migrate 6.2.2. Explicit --no-pglite fails with ECONNREFUSED at that unused port, as expected.

AI-assisted implementation and review, with the commands and results above actually run. No claim of human review or bounty award; this is submitted for maintainer evaluation.

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