node package manager
It’s your turn. Help us improve JavaScript. Take the 2017 JavaScript Ecosystem Survey »



Database migration tool for use in compound.js using semver for migrations. Build Status


Step 1. Install using npm:

npm install co-migrator --save

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

module.exports = function (compound) {
    return [

Step 3. Add schema to db/schema.js:

var migration = require('co-migrator').Schema.Migration;
schema.define('Migration', migration);

Step 4. Add model to app/models/migration.js:

module.exports = require('co-migrator').Models.Migration;


Create a new migration:

compound m create

You may also specify the schema(defaults to first schema encountered):

compound m create [schema]

A new migration will be saved in db/migrations/[version]. If a migration already exists for the current version of the application, a new migration will be incremented from the highest version of the current migration.


If the application is on version 1.2.3 and a migration is in db/migrations/1.2/1.2.3 called 1.2.3-mig.1.js, a new migration 1.2.3-mig.2.js will be placed in the same directory.

Migration example:


module.exports = {
    name        : String,
    description : String,
    writtenOn   : {
        type: Date,
        default: function () { return new Date(); }


var postSchema = require('../../schemas/post');
module.exports = function (compound, schema, models) {
    return {
        up   : function (done) {
            var Posts = schema.define('Posts', postSchema);
            schema.autoupdate(function (err) {
                if (err) { return done(err); }
                            name        : 'My First Blog Post',
                            description : 'My first blog post evar!!'
                }, done);
        down : function (done) {
            // Not used. 

Run Migrations

Run migrations:

compound m - defaults to first schema encountered

compound m up [schema]

Rollback migrations:

compound m down

You may also specify version and schema(defaults to first schema encountered)

compound m down [version] 

compound m down [version] [schema]