Registry / database / pg-flyway

pg-flyway

JSON →
library1.3.2jsnpmunverified

pg-flyway is a Node.js-based migration tool for PostgreSQL that mirrors the Flyway pattern without wrapping the Java or CLI version. The current stable version is 1.3.2, with frequent minor updates. It supports creating, migrating, and tracking SQL migrations with a dedicated history table. Unlike db-migrate or node-pg-migrate, pg-flyway emphasizes Flyway-like naming conventions, versioned migrations, and a CLI-first approach. It ships TypeScript definitions and requires Node.js >=14.

npm install pg-flyway
INSTALL
IMPORT
SIG · PG-FLYWAY
P
pg-flyway
databasejavascriptv1.3.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.

PgFlyway
import { PgFlyway } from 'pg-flyway'
const PgFlyway = require('pg-flyway')
ESM-only since v1; require() not supported.
createMigration
import { createMigration } from 'pg-flyway'
Programmatic API for creating a migration.
runMigrations
import { runMigrations } from 'pg-flyway'
Programmatic API for executing pending migrations.
getMigrationInfo
import { getMigrationInfo } from 'pg-flyway'
Programmatic API to retrieve migration status.

Initialize PgFlyway with database URL and migration directory, then run migrations and display info.

import { PgFlyway } from 'pg-flyway'; const flyway = new PgFlyway({ databaseUrl: process.env.DATABASE_URL ?? 'postgres://postgres:pgtoolspassword@localhost:5432/pgtoolsdatabase?schema=public', locations: ['./migrations'], historyTable: '__migrations' }); // Run pending migrations await flyway.migrate(); // Check info const info = await flyway.info(); console.log(info);
Debug
Known issues
gotchaESM only; requires Node >=14 and "type": "module" in package.json.
fix
Add "type": "module" to package.json or use .mjs file extension.
affects: >=1.0.0
gotchaMigrations must match pattern V<version>__<description>.sql; non-compliant files are ignored.
fix
Name files as V1__Init.sql or V202501151755__Init.sql (date format).
affects: >=1.0.0
gotchaHistory table defaults to __migrations; may conflict with existing tables.
fix
Specify custom historyTable in options.
affects: >=1.0.0
gotchaDatabase URL must include schema parameter when using non-public schema.
fix
Append ?schema=your_schema to the URL.
affects: >=1.0.0
Errors
Common errors & fixes
ERR_MODULE_NOT_FOUND: Cannot find module 'pg-flyway'
Using require() in an ESM context or missing import map.
fix
Use import (ESM) and ensure Node.js >=14 with "type": "module".
Error: Migration V1__Init.sql is missing the version prefix
File name does not match expected pattern V<version>__<description>.sql.
fix
Rename to V1__Init.sql or similar.
Error: connect ECONNREFUSED 127.0.0.1:5432
PostgreSQL not running or wrong host/port.
fix
Start Docker container or check DATABASE_URL.
Upgrade
Version history
1.3.2latest on npm
Audit
Dependencies
pgrequiredPostgreSQL client for database connections
commanderrequiredCommand-line argument parsing
Agent activity
13 hits · last 30 days
node
10
Amazon
1
Resources
pg-flyway — npm install pg-flyway · libregistry