pg-differ is a Node.js migration tool for PostgreSQL that compares database schemas (tables and sequences) against a metadata definition and generates SQL migration scripts. It supports updating columns without data loss, synchronizing indexes/constraints, and auto-generating schemas from existing database objects. The current stable version is 3.5.1, with releases following semantic versioning. Ships TypeScript types. Requires Node >=10.4.0. Key differentiator: declarative schema definition rather than imperative migration steps, offering both a CLI and programmatic API for safe, reversible database migrations.
npm install pg-differNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Connects to PostgreSQL, compares current database against a declared schema (table 'users'), and logs generated migration SQL.
Update call: const changes = await differ(client, { schema: [ ... ] });Replace `preserve: true` with `strategy: 'preserve'`.
Use `import { differ } from 'pg-differ'` and enable ESM resolution in tsconfig.Set `DATABASE_URL` environment variable or use `--url` flag.
Use import syntax instead: import { differ } from 'pg-differ'Use named import: import { differ } from 'pg-differ'Start PostgreSQL or configure connection using DATABASE_URL or pool options.