Registry / database / pg-node-migrations

pg-node-migrations

JSON →
library0.0.8jsnpmunverified

A PostgreSQL migration library for Node.js (v0.0.8) based on ThomWright's postgres-migrations, adding support for custom schema and migration table names. Migrations are defined in sequential SQL files (starting at 0_) and run in order with no down migrations. Requires Node >10.17.0 and supports PostgreSQL 9.4+. Ships TypeScript types. Key differentiator vs alternatives: simple file-based ordering, no timestamp reliance, and ability to run in custom schema/table.

npm install pg-node-migrations
INSTALL
IMPORT
SIG · PG-NODE-MIGRATIONS
P
pg-node-migrations
databasejavascriptv0.0.8
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.

migrate
import { migrate } from 'pg-node-migrations'
const { migrate } = require('pg-node-migrations')
Package ships TypeScript types and is ESM-compatible. CommonJS require may work but is not recommended.
loadMigrationFiles
import { loadMigrationFiles } from 'pg-node-migrations'
Used for validation of migration file ordering.
MigrationDirection
import type { MigrationDirection } from 'pg-node-migrations'
TypeScript type import for migration direction enum.

Shows basic usage of migrate() with custom schema/table, using database config object.

import { migrate } from 'pg-node-migrations'; import path from 'path'; async function runMigrations() { const dbConfig = { database: 'mydb', user: 'postgres', password: process.env.DB_PASSWORD ?? '', host: 'localhost', port: 5432, ensureDatabaseExists: true, defaultDatabase: 'postgres', }; const optionalConfig = { schemaName: 'mySchema', tableName: 'myMigrations', }; await migrate(dbConfig, path.join(__dirname, 'migrations'), optionalConfig); console.log('Migrations applied successfully'); } runMigrations().catch(console.error);
Debug
Known issues
breakingThe `ensureDatabaseExists` option defaults to `false` for backwards compatibility but may change to `true` in future versions.
fix
Explicitly set `ensureDatabaseExists: true` if you want the database to be created automatically.
affects: >=0.0.1
gotchaMigrations must start with a number followed by underscore (e.g., 0_create-table.sql) and be sequentially numbered without gaps.
fix
Ensure file names follow the pattern: <number>_<description>.sql, starting from 0.
affects: >=0.0.1
gotchaWhen passing a pg Client, Pool, or PoolClient to migrate, the database must already exist; ensureDatabaseExists is ignored.
fix
If using a client, create the database beforehand or use the config object instead.
affects: >=0.0.1
gotchaOnly SQL files are supported for migrations; other file types will be ignored.
fix
Place only .sql files in the migration directory.
affects: >=0.0.1
Errors
Common errors & fixes
Error: Migration files must be sequentially numbered
Migration files have gaps in numbering or duplicates.
fix
Rename files to ensure sequential order (e.g., 0_, 1_, 2_) with no missing numbers.
Error: ensureDatabaseExists is not a valid option when using a client
Passing a client object with ensureDatabaseExists in config.
fix
Remove ensureDatabaseExists from config when using client; the database must already exist.
Error: Cannot find module 'pg'
pg package is not installed.
fix
Run `npm install pg` to install the peer dependency.
Upgrade
Version history
0.0.8latest on npm
Audit
Dependencies
pgrequiredRequired for database connection
Agent activity
4 hits · last 30 days
node
4
Resources
pg-node-migrations — npm install pg-node-migrations · libregistry