Registry / database / larvitdbmigration-pg

larvitdbmigration-pg

JSON →
library0.2.3jsnpmunverified

A database migration tool for PostgreSQL, version 0.2.3. It manages database schema and content changes by running migration scripts in order, tracking the current version in a `db_versions` table. Migrations can be written as JavaScript (async functions) or SQL files. It integrates with the `larvitdb-pg` library and supports custom table names and script paths. Release cadence is low; updates focus on dependency fixes.

npm install larvitdbmigration-pg
INSTALL
IMPORT
SIG · LARVITDBMIGRATION-
L
larvitdbmigration-pg
databasejavascriptv0.2.3
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.

default (constructor)
const DbMigration = require('larvitdbmigration-pg');
import DbMigration from 'larvitdbmigration-pg';
Package does not ship ESM; only CommonJS require works.
Constructor options
const migration = new DbMigration({ dbDriver, tableName: 'my_table', migrationScriptPath: './migrations' });
const migration = new DbMigration(dbDriver);
Options must be an object with at least `dbDriver`. Other options are optional.
run() method
migration.run().then(() => console.log('done')).catch(err => console.error(err));
await migration.run(); // only works if wrapped in async function
run() returns a Promise. Use .then() or await.

Demonstrates how to initialize and run a migration using larvitdbmigration-pg with larvitdb-pg.

const DbMigration = require('larvitdbmigration-pg'); const Db = require('larvitdb-pg'); const dbDriver = new Db({ user: process.env.DB_USER ?? 'postgres', password: process.env.DB_PASSWORD ?? '', host: process.env.DB_HOST ?? 'localhost', port: parseInt(process.env.DB_PORT ?? '5432'), database: process.env.DB_NAME ?? 'mydb' }); const migration = new DbMigration({ dbDriver, tableName: 'db_version', migrationScriptPath: './dbmigration' }); migration.run() .then(() => console.log('Migration successful')) .catch(err => { console.error(err); process.exit(1); });
Debug
Known issues
breakingMigration scripts run synchronously in version order; running multiple instances concurrently can cause hangs due to row locking. Do not run migration scripts in parallel.
fix
Ensure only one instance runs migrations at a time (e.g., use a distributed lock or run during deployment).
affects: >=0.0.0
gotchaIf a .js migration file exists for a version, the corresponding .sql file is ignored. Both cannot be used for the same version number.
fix
Use only one type per version number (either .js or .sql, not both).
affects: >=0.0.0
deprecatedPackage uses `larvitdb-pg` which may have breaking changes between versions. Keep dependencies aligned.
fix
Check larvitdb-pg changelog and test after upgrades.
affects: >=0.1.0
Errors
Common errors & fixes
Error: Cannot find module 'larvitdb-pg'
Missing required peer dependency `larvitdb-pg`.
fix
Install larvitdb-pg: npm install larvitdb-pg
TypeError: migration.run is not a function
Importing incorrectly (e.g., using ESM import syntax).
fix
Use CommonJS require: const DbMigration = require('larvitdbmigration-pg');
Error: ECONNREFUSED
Database connection failed.
fix
Check database host/port credentials and ensure PostgreSQL is running.
Error: relation "db_version" does not exist
Migration table not created yet; run migration for the first time.
fix
Ensure migration script path is correct and run migration. The table will be auto-created.
Upgrade
Version history
0.2.3latest on npm
Audit
Dependencies
larvitdb-pgrequiredPrimary database driver for PostgreSQL
Agent activity
2 hits · last 30 days
node
2
Resources
larvitdbmigration-pg — npm install larvitdbmigration-pg · libregistry