Registry / database / dbmigrate

dbmigrate

JSON →
library0.1.2jsnpmunverified

A migration system for Node.js that supports MySQL and other databases. Version 0.1.2 is the current stable release with a slow release cadence. Key differentiators include a simple CLI and programmatic API, global or local installation, and support for custom migration table names. It is lightweight but lacks advanced features like seeding or multiple database drivers beyond MySQL. The package ships TypeScript types and is suitable for small to medium-sized projects that need basic schema migrations.

npm install dbmigrate
INSTALL
IMPORT
SIG · DBMIGRATE
D
dbmigrate
databasejavascriptv0.1.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.

MysqlMigration
const Migration = require('dbmigrate').MysqlMigration;
import { MysqlMigration } from 'dbmigrate';
dbmigrate is CommonJS-only; ESM import may fail. Use require() in Node.js.
dbmigrate
const dbmigrate = require('dbmigrate');
import dbmigrate from 'dbmigrate';
Package does not have a default export. Use require for all imports.
MigrationClass
exports.migrationClass = m20170927_113738_user_table;
export default class MyMigration extends Migration {}
Migrations must export a class property `migrationClass`; ES module syntax is not supported.

Shows basic setup, migration class structure, and CLI usage for dbmigrate with MySQL.

// Ensure dbmigrate is installed locally: npm install dbmigrate mysql2 // Create .migration.js configuration file: module.exports = { migrationPath: './migrations', dbms: 'mysql', connection: { user: process.env.DB_USER ?? 'root', password: process.env.DB_PASS ?? '', database: process.env.DB_NAME ?? 'test' }, migrationTableName: '_migrations' }; // Create a migration: // npx migrate create create_users_table // migrations/20250311_create_users_table.js: const Migration = require('dbmigrate').MysqlMigration; class m20250311_create_users_table extends Migration { up(callback) { this.connection.query( 'CREATE TABLE users (id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(255))', callback ); } down(callback) { this.connection.query('DROP TABLE users', callback); } } exports.migrationClass = m20250311_create_users_table; // Run migrations: // npx migrate up
Debug
Known issues
gotchaPackage name discrepancy: npm install uses 'dbmigrate', but GitHub repository and documentation may refer to 'db-migrate' or 'node-migrate'.
fix
Always use 'dbmigrate' as the package name when installing.
affects: >=0.0.0
gotchaMigrations must export a property named 'migrationClass', not a default export or named export.
fix
Use 'exports.migrationClass = MyMigrationClass;' at the end of each migration file.
affects: >=0.0.0
breakingMinimum Node.js version is 14.15.0. Older Node versions will not work.
fix
Update Node.js to >=14.15.0.
affects: >=0.1.0
gotchaGlobal installation requires npm link to work as CLI tool.
fix
Run 'npm install -g dbmigrate' then 'npm link dbmigrate' in your project directory.
affects: >=0.0.0
Errors
Common errors & fixes
Error: Cannot find module 'dbmigrate'
Package not installed or import path is wrong.
fix
Run 'npm install dbmigrate' and use require('dbmigrate') in your migration file.
Error: Module "dbmigrate" does not provide a "MysqlMigration" export
Using ES6 import syntax instead of CommonJS require.
fix
Use 'const Migration = require('dbmigrate').MysqlMigration;' instead of import.
TypeError: this.connection.query is not a function
Using 'this.connection' inside a static method or outside the class methods.
fix
Ensure up/down methods are instance methods and the class extends Migration.
Upgrade
Version history
0.1.2latest on npm
Audit
Dependencies
mysql2optionalRequired for MySQL database connections in migrations.
Agent activity
7 hits · last 30 days
node
6
Resources
dbmigrate — npm install dbmigrate · libregistry