fix: default db:generate to PGlite to remove postgres background dependency (#2) - #48
Open
mudassiralladatkhan wants to merge 1 commit into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates pgstrap generate to default to an in-memory PGlite-backed database so type/schema generation works without requiring a separately running PostgreSQL instance, and adds a regression test to cover the default behavior.
Changes:
- Default
generate()(and CLIpgstrap generate) topglite: true, while still allowing opt-out via--no-pglite. - Add
try...finallyteardown logic in the PGlite path to restoreDATABASE_URLand close resources. - Add a new Bun test ensuring default generation produces expected output files without external Postgres.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
src/generate.ts |
Defaults to PGlite and adds teardown logic around generate + schema dump. |
src/cli.ts |
Changes CLI --pglite default to true. |
tests/generate.default.test.ts |
Adds regression test for default generate behavior using temp migrations/output. |
Suppressed comments (1)
src/cli.ts:42
- The CLI command handler is
asyncbut does notawaitgenerate(), so yargs may consider the command finished early and errors can surface as unhandled rejections / incorrect exit codes. Also!!argv.pgliteis redundant (and can mis-coerce if argv is not a boolean).
yargs.option("pglite", { type: "boolean", default: true })
},
async (argv) => {
generate({ ...(await getProjectContext()), pglite: !!argv.pglite })
},
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+81
to
+85
| await dumpTree({ | ||
| targetDir: path.join(dbDir, "structure"), | ||
| defaultDatabase: "postgres", | ||
| schemas, | ||
| }) |
Comment on lines
+86
to
+93
| } finally { | ||
| server.close() | ||
| if (prevDbUrl === undefined) delete process.env.DATABASE_URL | ||
| else process.env.DATABASE_URL = prevDbUrl | ||
| if (typeof (db as any).close === "function") { | ||
| await (db as any).close() | ||
| } | ||
| } |
Comment on lines
+45
to
+49
| expect(fs.existsSync(zapatosFile)).toBe(true) | ||
| expect(fs.existsSync(path.join(structureDir, "table.sql"))).toBe(true) | ||
|
|
||
| fs.rmSync(tmp, { recursive: true, force: true }) | ||
| }) |
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.
@algora-pbc /claim #2
Closes #2
Summary
pgstrap generateand programmaticgenerate()calls to use an in-memoryPGlitedatabase instance sobun run db:generateworks without requiring an external PostgreSQL instance running in the background.--no-pglite(orpglite: false).try...finallyblock insrc/generate.tsto guarantee proper server teardown, database closure, andDATABASE_URLenvironment restoration.tests/generate.default.test.tsverifying thatgenerate()runs and produces types/schema dumps with default arguments without a live Postgres server.Verification
bun test(all tests passing)bun run build(builds dist cleanly)bun run format:check(passes format check)