co-migrate

mmm

npm install co-migrate
5 downloads in the last week
24 downloads in the last month

co-migrate

compound.js migrations extension based on node-migrate

Installation

Step 1. Install using npm:

npm install co-migrate --save

Step 2. Add co-migrate to config/autoload.js, for example:

module.exports = function (compound) {
    return [
        'ejs-ext',
        'jugglingdb',
        'seedjs',
        'co-logger',
        'co-migrate'
    ].map(require);
};

Usages

To create new migration step use:

compound m create MyNewMigrationName

New migration file will be located in the "/migrations" folder. "db" variable is available in your migration file.

Migration file example(for MongoDB adapter):

exports.up = function(next){

  db.collection('Event', function(err, collection){

    if(err){
      console.log("Cannot get collection Event")
      next(err);
    } else {
      collection.ensureIndex( { "from": 1 }, function(err){
        next(err);
      });
    }
  });

};

exports.down = function(next){

  db.collection('Event', function(err, collection){

    if(err){
      console.log("Cannot get collection Event")
      next(err);
    } else {
      collection.dropIndex( { "from": 1 }, function(err){
        next(err);
      });
    }
  });

};

To run migrations use:

compound m up

To roll back all migrations use:

compound m down

You can specify migration name for "up" and "down" commands.

Don't forget to add "/migrations/.migrate" file to ".gitignore"

npm loves you