Registry / database / migrationjs

migrationjs

JSON →
library0.4.12jsnpmunverified

A Node.js database migration system that allows creating and running migrations with up/down functions. Currently at version 0.4.12, it provides a CLI for generating migration files, migrating, and rolling back. Key differentiators include a schema builder with Blueprint for table operations (create, alter, drop), TypeScript support, and a simple batch-based migration tracking system. It supports MySQL, PostgreSQL, and SQLite. The package is minimal and lightweight but lacks features like seeding or advanced error handling.

npm install migrationjs
INSTALL
IMPORT
SIG · MIGRATIONJS
M
migrationjs
databasejavascriptv0.4.12
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.

Migration
import { Migration } from 'migrationjs'
const Migration = require('migrationjs').Migration
ESM-style import; CommonJS require is possible but not recommended.
Blueprint
import { Blueprint } from 'migrationjs'
import Blueprint from 'migrationjs'
Named export, not default.
Schema
import { Schema } from 'migrationjs'
const Schema = require('migrationjs').Schema
ESM import preferred. Schema is a class with static methods.

Shows how to define a migration class with up/down methods using Schema and Blueprint to create a 'users' table.

import { Migration, Blueprint, Schema } from 'migrationjs'; import { config } from 'dotenv'; config(); // Create a migration class (usually in a separate file) export default class CreateUsersTable extends Migration { async up() { await Schema.create('users', (table: Blueprint) => { table.id(); table.string('name'); table.timestamps(); }); } async down() { await Schema.dropIfExists('users'); } } // In your main file, run migrations using CLI: // migrationjs migrate // Or programmatically (not documented but possible via internals, avoid)
Debug
Known issues
gotchaMigration files must be placed in a 'migrations' directory by default; otherwise CLI will not find them.
fix
Create a 'migrations' folder in your project root, or configure the path in migrationjs.conf.json.
affects: >=0.0.0
gotchaThe 'down' method must exactly reverse the 'up' method; there is no validation and orphaned data may occur.
fix
Always implement a matching 'down' that drops/alters what 'up' created.
affects: >=0.0.0
breakingVersion 0.4.x changed the import style from default to named exports.
fix
Change imports: import { Migration } from 'migrationjs' instead of import Migration from 'migrationjs'.
affects: >=0.4.0 <0.5.0
deprecatedThe 'Schema.drop' method is deprecated; use 'Schema.dropIfExists' instead.
fix
Replace Schema.drop with Schema.dropIfExists to avoid errors when table doesn't exist.
affects: >=0.4.0
Errors
Common errors & fixes
Error: Cannot find module 'migrationjs'
Package not installed or not globally installed when using CLI.
fix
Install migrationjs locally: npm install migrationjs --save-dev, then use npx migrationjs migrate.
TypeError: Schema.create is not a function
Incorrect import: using default import instead of named import.
fix
Use import { Schema } from 'migrationjs'.
Migration file must export a class extending Migration
Exporting an object or function instead of a class.
fix
Export default a class that extends the Migration class.
Upgrade
Version history
0.4.12latest on npm
Audit
Dependencies
mysql2optionalfor MySQL database connections
pgoptionalfor PostgreSQL database connections
better-sqlite3optionalfor SQLite database connections
Agent activity
9 hits · last 30 days
node
8
Resources
migrationjs — npm install migrationjs · libregistry