migrations

Data agnostic migrations

node-migrations

Data agnostic migrations

npm i migrations

In order to use this module you need to have a bootstrap file (e.g. migrations.js) where you can initialize db, specify your own meta storage adapter and so on.

var Migrations = require('migrations'),
  MetaFile = require('migrations/lib/meta/file');
 
module.exports = new Migrations({
  dir: __dirname + '/migrations', // directory with migration files 
  meta: new MetaFile({path: __dirname + '/migrations.json'}) // meta information storage 
});
 
module.exports.run();

You can specify your custom store of meta data, e.g.:

var Migrations = require('migrations'),
  meta = {};
 
// Meta Storage has very basic interface: 
var storage = {
  getfunction(cb) { cb(null, meta) },
  setfunction(valuecb) { meta = value; cb() }
};
 
 
module.exports = new Migrations({
  dir: __dirname + '/migrations',
  meta: storage // custom storage 
});
 
module.exports.run();

You can put a special task in package.json file:

{
  "name": "my-project",
  "scripts": {
    "migrate": "node migrations.js"
  }
}

and then you be able to do npm run migrate. Another option is to add shebang to the migrations executable and run it in a manual way.

  Usage: migrations.js [options]
 
  Options:
 
    -h, --help  output usage information
    --up      Migrate up
    --down    Migrate down
    --create  Create empty migration file
    --count   Migrate particular number of migration
    --revert  Revert last migration