Registry / database / migratio

migratio

JSON →
library2.0.3jsnpmunverified

migratio is a lightweight, automated migration tool for PostgreSQL with support for both SQL and JavaScript migration files. The current stable version is 2.0.3, released with an engine requirement of Node.js >=4. It runs migrations in transactions with table-level locking to ensure atomic batch execution. Key differentiators include support for async/await and generators out of the box, configurable defaults via package.json, and a non-verbose API with current, up, and down commands. The package is published on npm and distributed as CommonJS.

npm install migratio
INSTALL
IMPORT
SIG · MIGRATIO
M
migratio
databasejavascriptv2.0.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
✓ const migratio = require('migratio');
✗ import migratio from 'migratio';
migratio is a CommonJS module; it does not have a named or default ES module export.
up
✓ const { up } = require('migratio');
up, down, and current are methods on the default export object.
down
✓ const { down } = require('migratio');
✗ import { down } from 'migratio';
ESM import does not work; use destructuring from CommonJS require.
current
✓ const { current } = require('migratio');

Demonstrates how to require migratio, connect to Postgres, and run current/up/down commands with verbose output.

const migratio = require('migratio'); const connection = process.env.DATABASE_URL ?? 'postgres://localhost/db'; // Show current batch migratio.current({ connection, verbose: true }) .then(() => console.log('Done')) .catch(err => console.error(err)); // Apply all pending migrations migratio.up({ connection, verbose: true }) .then(() => console.log('Migration applied')) .catch(err => console.error(err)); // Rollback latest batch migratio.down({ connection, verbose: true }) .then(() => console.log('Migration rolled back')) .catch(err => console.error(err));
Debug
Known issues
gotchaMigration files must be named with a leading numeric revision (e.g., 000001-init.sql). Files with non-numeric prefixes are ignored.
fix
Ensure all migration files start with digits followed by a hyphen.
affects: *
gotchaMigrations run in a transaction with a lock on the migrations table. If any migration fails, the entire batch is rolled back.
fix
Use the 'unsafe' option to disable locking, but be aware of potential concurrency issues.
affects: *
deprecatedThe default database connection uses process.env.DATABASE_URL. Fallback to hardcoded string is not recommended.
fix
Set the DATABASE_URL environment variable or pass 'connection' explicitly.
affects: *
gotchaNode.js >=4 is required. No support for older Node versions.
fix
Upgrade Node to version 4 or later.
affects: >=2.0.0
Errors
Common errors & fixes
TypeError: migratio.up is not a function
Using ESM import syntax (import) with a CommonJS module.
fix
Use const migratio = require('migratio'); instead of import.
Error: Cannot find module 'migratio'
migratio not installed or not in node_modules.
fix
Run 'npm install --save migratio' in your project directory.
Error: ER_ACCESS_DENIED_ERROR: Access denied for user 'root'@'localhost' (using password: YES)
Connection string uses wrong credentials. (Note: migratio is for Postgres, not MySQL, but similar error may occur).
fix
Ensure connection string is correct for your Postgres instance, e.g., 'postgres://user:password@localhost:5432/db'.
Error: Cannot find module 'co'
co is required only if you use generator functions in JS migrations.
fix
Install co: npm install --save co, or convert generator functions to async/await.
Upgrade
Version history
2.0.3latest on npm
Audit
Dependencies
pg-promiserequiredPostgreSQL database connectivity
cooptionalWraps generator functions in migration files
Agent activity
9 hits · last 30 days
node
8
Resources
migratio — npm install migratio · libregistry