npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

node-db-migrator

v0.1.8

Published

a node database migrator

Downloads

31

Readme

node db migrator

Node.js Database Migration

Why another db migrator

  • Migration between multiple database

Support migration from one mysql database to another mysql database, or even to a mongo database

  • Script based migration

Support javascript migration script besides SQL migration script. Provide extreme flexibility to data migration.

  • Daemon to handle delta data

Support spin up a daemon to handle delta data. Allows data migration for some specific situation and parameters.

Installation

Install globally:

npm install -g node-db-migrator

Install locally

npm install node-db-migrator

Executable location: node_modules/node-db-migration/bin/node-db-migrator

Usage

Configuration

Before start the migration, create a database.json file.

Example:

{
  "defaultDb": "mysql",

  "mysql": {
    "driver": "mysql",
    "user": "root",
    "password": "yourpassword",
    "database": "node_db_migration",
    "host": "localhost",
    "multipleStatements": true
  },

  "mongo": {
    "driver": "mongodb",
    "database": "node_db_migration",
    "host": "localhost"
  }

}

Create a migration script

node-db-migrator create "your file name"

A new migration script will be created in your migration folder. By default the folder is your_workspace/migrations. Add code to the scripts to create a new migration.

Run migrations

Run all migrations

node-db-migrator up

Only migrations that all not run yet will be run. If there're multiple migrations to be run, they will be run sequentially according to their creation time.

Run specific migration

node-db-migrator up migration_file_name

Revert migrations

Revert all migrations

node-db-migrator down

All migrations that are run already will be reverted.

Revert specific migration

node-db-migrator down migration_file_name

Create a triggering script

node-db-migrator trigger "your trigger script name"

Create a triggering script to handle delta data.

Notice: a token will be shown in the terminal, you can use it to refer to this triggering script.

What is triggering script?

Triggering script is used to simplify the double write. Sometimes it's very hard to implement a double write in your code, then you can think about using a triggering script.

When writing data, you called the API of triggering script and passed the parameters needed. The triggering script will do everything else.

For example: You are modifying changing column info to new_info in Customer table. In your code you can do:

// pseudo code
triggerMigration(
  token /*your migration token*/,
  {customerId: customer_id} /*params*/
);

Then in node db migrator's daemon, it will catch this request and do the migration.

A common triggering migration script will look like this:

exports.trigger = function(db, params, callback) {
  var customerId = params.customer_id;
  db.mysql.query(
    'some sql where customer_id = ?',
    [customerId],
    callback
  );
};

Spin up daemon

node-db-migrator daemon

Spin up a daemon to listen to request to triggering migrations. By default it will spin up an http server (port: 8899) and a kafka consumer (topic: kafka_node_db_migration).

Other operations about daemon

# list all daemon
node-db-migrator daemon list
# stop specific daemon
node-db-migrator daemon stop [daemon_id]
# stop all daemon
node-db-migrator daemon stopall

Options

There're several options when using the node db migrator

-v, --version

Print version info.

-m, --migrations-dir

The directory containing your migration files. [default: "workspace/migrations"]

-d, --migrations-database

Set the path of the migration table, which stores the migration history. [default: "workspace/db"]

-c, --db-config

Location of the database.json file. [default: "workspace/database.json"]

-u, --db-in-use

Database might in use (mysql,mongo). [default: "mysql"]

-p, --port

Port number when running daemon. [default: "8899"]

--sql-file

Automatically create two sql files for up and down statements in /sqls and generate the javascript code that loads them. [default: false | To be implemented]

--dry-run

Prints the SQL but doesn't run it. [default: false | To be implemented]