Registry / database / megrim

megrim

JSON →
library2.1.0jsnpmunverified

Migration Tool for Postgres databases in node.js. Version 2.1.0 provides a simple migration framework using timestamped SQL files. It offers a CLI with add-migration and migrate commands, and a programmatic API via require('megrim'). Migrations are stored in schema/$timestamp-$name.sql and tracked in a schema_info table. Compared to more feature-rich tools like node-pg-migrate or Knex, megrim is minimal and does not support TypeScript, callbacks instead of Promises, and relies on the DATABASE_URL environment variable. It has been stable with minimal updates, suggesting maintenance mode.

npm install megrim
INSTALL
IMPORT
SIG · MEGRIM
M
megrim
databasejavascriptv2.1.0
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.

megrim
const megrim = require('megrim');
import megrim from 'megrim';
Package uses CommonJS and does not provide ESM exports. The require() pattern is correct for Node.js environments.
megrim function
megrim(path, connection, callback);
megrim(path, connection).then(...);
API uses callbacks, not Promises. Do not expect a Promise-based interface.

Shows how to programmatically run migrations using the megrim function with a callback.

// Ensure DATABASE_URL is set, e.g., postgres://user:pass@localhost/db const megrim = require('megrim'); const path = './schema'; // directory containing migration files const connection = process.env.DATABASE_URL; megrim(path, connection, (err, result) => { if (err) { console.error('Migration failed:', err); } else { console.log('Migrations run:', result); } });
Debug
Known issues
deprecatedmegrim uses callback-based API which is considered outdated.
fix
Consider using a migration tool with Promise/async support like node-pg-migrate.
affects: >=0.0.0
gotchaMigrations must be named in YYYYMMDDHHMMSS-description.sql format. Other patterns are ignored.
fix
Ensure files follow the timestamp format, e.g., 20250321120000-create-users.sql.
affects: >=0.0.0
gotchaDATABASE_URL environment variable must be set; otherwise migrations fail silently or with unclear errors.
fix
Set DATABASE_URL before running migrate command or passing connection programmatically.
affects: >=0.0.0
gotchaThe package name 'megrim' may be confused with 'megrim' typo; not related to 'migrate' or 'knex'.
fix
Double-check the package name; ensure you are using the correct migration tool.
affects: >=0.0.0
Errors
Common errors & fixes
Error: Cannot find module 'megrim'
megrim is not installed or not in node_modules
fix
Run npm install megrim --save and ensure the module is listed in package.json.
TypeError: megrim is not a function
Incorrect import (e.g., using default import in an ESM context or mispelling)
fix
Use const megrim = require('megrim'); and ensure no typos in the variable name.
error: relation "schema_info" does not exist
The schema_info table tracking migrations has not been created
fix
Run the migrate command once to create the schema_info table, or create it manually with: CREATE TABLE schema_info (version VARCHAR(255) PRIMARY KEY, applied_at TIMESTAMP DEFAULT NOW());
Upgrade
Version history
2.1.0latest on npm
Audit
Dependencies
pgrequiredPeer dependency required for PostgreSQL database connectivity
Agent activity
2 hits · last 30 days
node
2
Resources
packagemegrim
megrim — npm install megrim · libregistry