feat(generate): default to embedded PGlite when no PostgreSQL connection is configured - #63
Open
Furox-Art wants to merge 2 commits into
Open
feat(generate): default to embedded PGlite when no PostgreSQL connection is configured#63Furox-Art wants to merge 2 commits into
Furox-Art wants to merge 2 commits into
Conversation
…ion is configured pgstrap already shipped an opt-in `--pglite` mode, but `pgstrap generate` still required a running PostgreSQL server unless the flag was passed, which made the zero-config onboarding flow impossible offline. Now the default is automatic: - explicit `--pglite` / `--no-pglite` always wins - otherwise PGlite is used unless a PostgreSQL connection is configured through the environment (DATABASE_URL, DATABASE_URI, PG_URI or POSTGRES_HOST) Also fixes resource handling in the PGlite path: the temporary pg-gateway server is now closed in a `finally` block (awaited) and server errors no longer crash the process via an unhandled 'error' event. Closes seveibar#2 Signed-off-by: Furox-Art <Furox-Art@users.noreply.github.com>
Review follow-ups: POSTGRES_URI has higher precedence than DATABASE_URL in pg-schema-dump, so it must count as a configured connection and be overridden in the PGlite path together with PG_URI and DATABASE_URI. Also closes the PGlite instance in the finally block (covers migration failures) and awaits the CLI generate call. Signed-off-by: Furox-Art <Furox-Art@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #2
/claim #2
Summary
pgstrap generateno longer requires a running PostgreSQL server by default.The PGlite mode that already existed behind
--pglitebecomes the automaticdefault whenever no external PostgreSQL connection is configured.
Behavior
--pglitepassed--no-pglitepassedThe auto-detection checks every variable that pg-connection-from-env and
pg-schema-dump honor, including
POSTGRES_URIwhich has higher precedencethan
DATABASE_URL— so zapatos types and the structure dump always comefrom the same database.
Resource handling fixes
awaitedfinallyblock.finally(also covers migrationfailures — previously an error there leaked the instance).
listen()rejects throughserver.once("error", reject)instead ofthrowing from an event handler.
awaitsgenerate(...)so errors surface as a clean exit code.Tests
generate.auto-pglite.test.ts— with no flag and no connection env,generation completes offline and produces both the zapatos types and the
structure dump.
bun test→ 4 pass, 0 fail.tsc --noEmitclean insrc/.biome formatclean.