Skip to content

fix: default db:generate to PGlite to remove postgres background dependency (#2) - #48

Open
mudassiralladatkhan wants to merge 1 commit into
seveibar:mainfrom
mudassiralladatkhan:fix/default-generate-pglite
Open

fix: default db:generate to PGlite to remove postgres background dependency (#2)#48
mudassiralladatkhan wants to merge 1 commit into
seveibar:mainfrom
mudassiralladatkhan:fix/default-generate-pglite

Conversation

@mudassiralladatkhan

@mudassiralladatkhan mudassiralladatkhan commented Aug 13, 2026

Copy link
Copy Markdown

@algora-pbc /claim #2

Closes #2

Summary

  • Defaults pgstrap generate and programmatic generate() calls to use an in-memory PGlite database instance so bun run db:generate works without requiring an external PostgreSQL instance running in the background.
  • Preserves the ability to target an external Postgres instance by passing --no-pglite (or pglite: false).
  • Wraps generation and schema dump in a try...finally block in src/generate.ts to guarantee proper server teardown, database closure, and DATABASE_URL environment restoration.
  • Adds regression test coverage in tests/generate.default.test.ts verifying that generate() 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)

Copilot AI lite review requested due to automatic review settings August 13, 2026 15:42

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 CLI pgstrap generate) to pglite: true, while still allowing opt-out via --no-pglite.
  • Add try...finally teardown logic in the PGlite path to restore DATABASE_URL and 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 async but does not await generate(), so yargs may consider the command finished early and errors can surface as unhandled rejections / incorrect exit codes. Also !!argv.pglite is 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 thread src/generate.ts
Comment on lines +81 to +85
await dumpTree({
targetDir: path.join(dbDir, "structure"),
defaultDatabase: "postgres",
schemas,
})
Comment thread src/generate.ts
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 })
})
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

2 participants