Registry / database / pgmagmig

pgmagmig

JSON →
library0.1.2jsnpmunverified

PostgreSQL migration tool with integrated schema differ, powered by PGlite (PostgreSQL compiled to WASM). Current stable version 0.1.2. Schema extraction, DDL generation, diffing, and diff validation run in-process against PGlite without needing an external PostgreSQL server. Features automatic diff validation via round-tripping, hazard annotations for destructive operations, YAML migration drafting, and an ephemeral database mode for tools like Prisma. Requires Node.js >=20.

npm install pgmagmig
INSTALL
IMPORT
SIG · PGMAGMIG
P
pgmagmig
databasejavascriptv0.1.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

cli
npx pgmagmig <command>
The package is primarily a CLI tool; no programmatic API is documented.
main
import { migrate } from 'pgmagmig'
const pgmagmig = require('pgmagmig')
The package is ESM-only; CJS require() will fail.
migrate
import { migrate } from 'pgmagmig'
import migrate from 'pgmagmig'
migrate is a named export, not default.

Shows bootstrapping, drafting a migration from a SQL file, and applying migrations to a database.

// Initialize migration directory await $`npx pgmagmig bootstrap --migrations-dir ./migrations`; // Create a schema file await $`echo "CREATE TABLE users (id SERIAL PRIMARY KEY, name text NOT NULL);" > schema.sql`; // Draft a migration await $`npx pgmagmig draft-migration --migrations-dir ./migrations --to-sql schema.sql --title "Add users" --allow-hazards all`; // Apply to a real PostgreSQL database await $`npx pgmagmig migrate --migrations-dir ./migrations --database-url ${process.env.DATABASE_URL ?? 'postgres://localhost/mydb'}`;
Debug
Known issues
gotchaNode.js version 20 or later is required due to native ESM and WASM dependencies.
fix
Use Node.js >=20
affects: <0.1.0
deprecatedThe `generate` command is an alias for `diff --from-empty` and may be removed in a future version.
fix
Use `pgmagmig diff --from-empty --to-sql schema.sql` instead.
affects: >=0.1.0
breakingMigration files are YAML with `.yaml` extension; YAML is required, not JSON.
fix
Ensure migration files are valid YAML (`.yaml` extension).
affects: >=0.1.0
gotchaSequential numbering is enforced strictly; gaps in migration numbers cause errors.
fix
Maintain consecutive numerical prefixes (e.g., 0001, 0002).
affects: >=0.1.0
gotchaThe `--allow-hazards all` flag is required when drafting migrations that include destructive operations (e.g., DROP TABLE).
fix
Add `--allow-hazards all` to `draft-migration` command, or specify specific hazard types.
affects: >=0.1.0
Errors
Common errors & fixes
Error [ERR_MODULE_NOT_FOUND]: Cannot find module 'pgmagmig'
Using CommonJS require() with an ESM-only package.
fix
Use import statement or npx: `import { migrate } from 'pgmagmig'` or `npx pgmagmig`
Error: Node.js version 18.x is not supported. Please upgrade to Node.js 20 or later.
Running on an older Node.js version (<20).
fix
Upgrade Node.js to version 20 or later.
ValidationError: Migration number 0002 found, but 0001 is missing.
Migration files must have consecutive numbering; skipping a number causes an error.
fix
Ensure migration files are named sequentially starting from 0001.yaml.
Upgrade
Version history
0.1.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
10 hits · last 30 days
node
8
Amazon
1
Resources
pgmagmig — npm install pgmagmig · libregistry