Registry / database / pg-migrator

pg-migrator

JSON →
library2.0.1jsnpmunverified

pg-migrator is a command-line tool for PostgreSQL database migrations, version 2.0.1. It supports forward and backward migrations, step-by-step or to a specific version, with transactional (all-or-nothing) execution. It searches subfolders for SQL scripts named in 'x-y.sql' format. Compared to other tools like Flyway or node-pg-migrate, it is simpler, purely CLI-based, and does not require a configuration file beyond the connection string. Its release cadence is low (last release 2019), but it remains functional for basic migration needs.

npm install pg-migrator
INSTALL
IMPORT
SIG · PG-MIGRATOR
P
pg-migrator
databasejavascriptv2.0.1
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.

pg-migrator CLI
npx pg-migrator postgres://user:pass@localhost/db
import pgMigrator from 'pg-migrator'
pg-migrator is a CLI tool, not a library; use npx or global install.

Global install, run migration with connection string, optionally specify version or step forward/backward.

npm install -g pg-migrator # Create migration scripts in current directory: # 1-2.sql: creates a table # 2-3.sql: alter table # Ensure backward scripts (2-1.sql, 3-2.sql) if needed. pg-migrator postgres://user:password@localhost/testdb pg-migrator postgres://user:password@localhost/testdb 15 pg-migrator postgres://user:password@localhost/testdb +1 pg-migrator postgres://user:password@localhost/testdb -1
Debug
Known issues
gotchaMigration scripts must follow naming convention 'x-y.sql' (e.g., 1-2.sql for forward, 2-1.sql for backward). Other files ignored.
fix
Rename files to match pattern. Ensure forward and backward scripts exist for each version.
affects: >=1.0.0
gotchaMigration is transactional: all scripts in a single migration step run in a transaction. Failure rolls back entire step.
fix
Ensure each script is transactional-safe (no VACUUM, CREATE INDEX CONCURRENTLY, etc.)
affects: >=1.0.0
gotchaConnection string must be full URI: postgres://user:pass@host:port/db. Incomplete strings cause errors.
fix
Use complete connection string including port if non-default.
affects: >=1.0.0
deprecatedSince version 2.0.0, the CLI no longer supports the --help flag for detailed usage; refer to README.
fix
Check README GitHub for CLI options.
affects: >=2.0.0
Errors
Common errors & fixes
Error: Could not find migration script 'x-y.sql'
Missing forward or backward script for requested step.
fix
Create the required 'x-y.sql' file in the current directory or subfolders.
error: password authentication failed for user
Incorrect username/password in connection string.
fix
Verify credentials and ensure the user has access to the database.
error: relation "some_table" does not exist
Migration script references a table that doesn't exist yet.
fix
Order scripts correctly: create tables in earlier version scripts before using them in later ones.
Upgrade
Version history
2.0.1latest on npm
Audit
Dependencies
pgrequiredRequired for PostgreSQL connection
Agent activity
12 hits · last 30 days
node
10
Amazon
1
Resources
pg-migrator — npm install pg-migrator · libregistry