DEV.co
Open-Source Databases · salsita

node-pg-migrate

node-pg-migrate is a Node.js tool that manages database schema changes for PostgreSQL and compatible databases like CockroachDB. It lets teams write migrations as JavaScript code that can be applied forward and (sometimes) automatically reversed, avoiding manual SQL scripts.

Source: GitHub — github.com/salsita/node-pg-migrate
1.5k
GitHub stars
194
Forks
TypeScript
Primary language
MIT
License (OSI-approved)

Key facts

Objective fields from the source. Values we can't verify are shown as “Unknown” rather than guessed.

FieldValue
Repositorysalsita/node-pg-migrate
Ownersalsita
Primary languageTypeScript
LicenseMIT — OSI-approved
Stars1.5k
Forks194
Open issues50
Latest releasev8.0.4 (2025-12-11)
Last updated2026-07-08
Sourcehttps://github.com/salsita/node-pg-migrate

What node-pg-migrate is

A TypeScript-based migration manager for PostgreSQL 13+ that provides a programmatic API (pgm object) to generate idempotent SQL, supports async operations within migrations, and tracks applied migrations in the database. Built on the pg driver and requires Node.js 20.11+.

Quickstart

Get the node-pg-migrate source

Clone the repository and explore it locally.

terminalbash
git clone https://github.com/salsita/node-pg-migrate.gitcd node-pg-migrate# follow the project's README for install & configuration

Need it deployed, integrated, or customized instead? DEV.co ships production installs.

Best use cases

Multi-environment schema management

Use for teams needing consistent schema deployments across dev, staging, and production without manual SQL coordination. Programmatic approach prevents drift and human error.

Complex migrations with business logic

Ideal when migrations require async operations (data transformations, API calls) or conditional logic; avoids the crippling constraints of pure SQL-based tools.

CockroachDB and PostgreSQL portability

Leverage for projects using PostgreSQL today but considering CockroachDB, or those already hybrid; tested against both.

Implementation considerations

  • Install pg driver separately (peer dependency); ensure it matches your PostgreSQL server version.
  • Set DATABASE_URL environment variable for all environments; use secrets management (e.g., .env files in dev, CI/CD secrets in prod).
  • Write reversible up/down functions early; do not rely solely on automatic downgrade inference for production schemas.
  • Test migrations against a replica of production schema and data volume before apply.
  • Use migration naming conventions strictly (timestamps prefixed) to avoid ordering conflicts in teams.

When to avoid it — and what to weigh

  • Non-PostgreSQL databases required — Tool is explicitly PostgreSQL-first. While CockroachDB compatibility is tested, use of other SQL databases is unsupported and untested.
  • Pre-Node.js 20.11 environments — Hard requirement of Node.js 20.11+; cannot backport to older runtime versions.
  • Seeking automated downward migrations — Downgrades are inferred 'sometimes' per docs—no guarantee. Requires explicit down() functions for safety-critical schemas.
  • Zero-downtime deployment needs — Tool provides no built-in orchestration for zero-downtime deploys. Requires external coordination and careful index/constraint ordering.

License & commercial use

MIT License—permissive, OSI-approved. Allows commercial use, modification, and distribution with attribution and no warranty.

MIT is a standard permissive OSI license. Commercial use is permitted. No copyleft or enterprise licensing restrictions detected. No additional proprietary tiers or dual licensing stated in README.

DEV.co evaluation signals

Editorial assessment — not user reviews. Directional, with an explicit confidence level.

SignalAssessment
MaintenanceActive
DocumentationAdequate
License clarityClear
Deployment complexityLow
DEV.co fitStrong
Assessment confidenceHigh
Security considerations

Migrations execute raw SQL generated from user code; no built-in protection against SQL injection if user functions construct dynamic SQL carelessly. DATABASE_URL contains credentials—must not be committed to version control; use environment variable injection in CI/CD. No explicit mention of transaction safety or rollback guarantees in README; requires review of rollback behavior on error.

Alternatives to consider

Flyway

Multi-database, battle-tested, compiled JVM tool with strong lock mechanisms; trade-off is no Node.js native runtime and less programmatic flexibility.

Liquibase

Supports many databases and XML/JSON/YAML syntax; enterprise features (approval workflows, audit); heavier than node-pg-migrate and not Node-native.

TypeORM migrations

Integrated into TypeORM ORM; simpler if already using TypeORM; less flexible for non-ORM use cases and PostgreSQL-specific features.

Software development agency

Build on node-pg-migrate with DEV.co software developers

Review the full documentation at salsita.github.io/node-pg-migrate and test a sample migration on a dev PostgreSQL instance. Confirm rollback behavior and DATABASE_URL secret handling for your CI/CD pipeline.

Talk to DEV.co

Related open-source tools

Surfaced by semantic similarity across the DEV.co open-source index.

Related on DEV.co

Explore the category and the services that help you build with it.

node-pg-migrate FAQ

Can I use node-pg-migrate without TypeScript?
Yes. Project is written in TypeScript but distributed as JavaScript. Use .js migration files as shown in README; CommonJS or ES modules supported.
How do I rollback a migration in production?
Write explicit down() function in migration file; run npm run migrate down. Automatic down inference is not guaranteed; manual functions are safest for production.
Does node-pg-migrate lock the database during migrations?
Not explicitly stated in README. Requires review of source code and PostgreSQL lock behavior. Large index/constraint operations may lock tables; test on staging first.
Can I use this with CockroachDB?
Yes; README explicitly mentions CockroachDB support and CI runs CockroachDB tests. Not all PostgreSQL-specific features may apply; verify compatibility per feature.

Software development & web development with DEV.co

DEV.co is a software development agency delivering custom software development services to companies building on open source. Our software developers and web developers design, integrate, and ship production systems — spanning web development, APIs, AI, data, and cloud. If node-pg-migrate is part of your open-source databases roadmap, our team can implement, customize, migrate, and maintain it.

Evaluate node-pg-migrate for your team

Review the full documentation at salsita.github.io/node-pg-migrate and test a sample migration on a dev PostgreSQL instance. Confirm rollback behavior and DATABASE_URL secret handling for your CI/CD pipeline.