feat(pgpm): pluggable migration-driver contract + generic plugin loader#1352
Merged
Conversation
Adds the driver-plugin seam so pgpm can target alternate backends (PGlite, and later others) without pgpm core/CLI depending on any backend. - @pgpmjs/types: PgpmDriverConfig / PgpmDriverFactory / PgpmDriverSession / PgpmDriverCapabilities contract + PgpmOptions.driver (undefined = built-in pg). - pgpm/cli: activateDriver() resolves the plugin from the CONSUMER's node_modules via createRequire (dual CJS/ESM safe, no bare require in ESM output) and calls its createPgpmDriver export. driverOverrideFromArgv maps --pglite / --driver. - 13 unit tests (arg mapping, config precedence/merge, missing-plugin + non-plugin errors, server-path passthrough). Pure additive plumbing; no backend deps in pgpm; server path unchanged.
Contributor
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
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.
Summary
Step 1 of making pgpm pluggable so it can target alternate backends (PGlite now, others like Turso/libSQL later) without pgpm core/CLI depending on any backend. This PR is pure additive plumbing — the built-in
pg(server) path is unchanged (adriveris undefined by default).The contract (
@pgpmjs/types): a driver plugin is any package exporting a well-known factory. pgpm depends only on this interface, never on a backend or its deps.capabilities(createdb/dump/serverLifecycle/multiConnection) will later let the CLI generically skip server-only steps instead of hard-codingif (pglite).The loader (
pgpm/cli/src/utils/driver.ts): resolves the plugin from the consumer's project, exactly like ESLint/Babel resolve plugins — pgpm ships zero backend deps.createRequirefromnode:module, not barerequire.resolve/await import(). In the ESM bundle (module: es2022) a barerequireisundefinedat runtime; in the CJS bundle tsc downlevelsimport()back torequire.createRequirebehaves identically in both — verified againstdist/anddist/esm/.driverOverrideFromArgvmaps--pglite(bare → in-memory),--pglite=<dir>(→options.dataDir), and--driver <pkg>;--pglitewins over--driver.resolveDriverConfighandles precedence (override beatspgpm.json) and option merging for the same plugin.npm ihint) and "does not export createPgpmDriver".Tests
13 unit tests in
pgpm/cli/__tests__/driver.test.ts(arg mapping, config precedence/merge, server-path passthrough, missing-plugin + non-plugin errors). Both@pgpmjs/typesandpgpm/clibuild (CJS + ESM).Not in this PR (follow-ups per the plan)
Wiring
activateDriverintodeploy/verify/revertwith capability-driven guards;@pgpmjs/pglite-adapterimplementingcreatePgpmDriver;pgpm init --pglite; thepglite/*boilerplate family. Then Turso/libSQL as a separate plugin.Link to Devin session: https://app.devin.ai/sessions/424b76f81a60499493ac946b57136ad9
Requested by: @pyramation