index.js
function performMigration(direction, migrateTo, next) {
		if (!next &&
	    Object.prototype.toString.call(migrateTo) === '[object Function]') {
	    next = migrateTo;
	    migrateTo = undefined;
	  }

		if (!next) {
			next = function(err) {
				if (err) {
					console.error(err);
					process.exit(1);
				} else {
					process.exit();
				}
			}
		}

		var db = require('./lib/db');
		db.getConnection(dbConfig || require(process.cwd() + path.sep + configFileName)[dbProperty], function (err, db) {
			if (err) {
				return next(new verror.WError(err, 'Error connecting to database'));
			}
			var migrationCollection = db.migrationCollection,
					dbConnection = db.connection;

			migrationCollection.find({}).sort({num: -1}).limit(1).toArray(function (err, migrationsRun) {
				if (err) {
					return next(new verror.WError(err, 'Error querying migration collection'));
				}

				var lastMigration = migrationsRun[0],
					lastMigrationNum = lastMigration ? lastMigration.num : 0;

				migrate({
					migrationTitle: 'migrations/.migrate',
					db: dbConnection,
					migrationCollection: migrationCollection
				});
				migrations(direction, lastMigrationNum, migrateTo).forEach(function(path){
					var mod = require(process.cwd() + '/' + path);
					migrate({
						num: parseInt(path.split('/')[1].match(/^(\d+)/)[0], 10),
						title: path,
						up: mod.up,
						down: mod.down});
				});

				//Revert working directory to previous state
				process.chdir(previousWorkingDirectory);

				var set = migrate();

				set.on('migration', function(migration, direction){
					log(direction, migration.title);
				});

				set.on('save', function(){
					log('migration', 'complete');
					return next();
				});

				set[direction](null, lastMigrationNum);
			});
		});
	}
function performMigration(direction, migrateTo, next) {
		if (!next &&
	    Object.prototype.toString.call(migrateTo) === '[object Function]') {
	    next = migrateTo;
	    migrateTo = undefined;
	  }

		if (!next) {
			next = function(err) {
				if (err) {
					console.error(err);
					process.exit(1);
				} else {
					process.exit();
				}
			}
		}

		var db = require('./lib/db');
		db.getConnection(dbConfig || require(process.cwd() + path.sep + configFileName)[dbProperty], function (err, db) {
			if (err) {
				return next(new verror.WError(err, 'Error connecting to database'));
			}
			var migrationCollection = db.migrationCollection,
					dbConnection = db.connection;

			migrationCollection.find({}).sort({num: -1}).limit(1).toArray(function (err, migrationsRun) {
				if (err) {
					return next(new verror.WError(err, 'Error querying migration collection'));
				}

				var lastMigration = migrationsRun[0],
					lastMigrationNum = lastMigration ? lastMigration.num : 0;

				migrate({
					migrationTitle: 'migrations/.migrate',
					db: dbConnection,
					migrationCollection: migrationCollection
				});
				migrations(direction, lastMigrationNum, migrateTo).forEach(function(path){
					var mod = require(process.cwd() + '/' + path);
					migrate({
						num: parseInt(path.split('/')[1].match(/^(\d+)/)[0], 10),
						title: path,
						up: mod.up,
						down: mod.down});
				});

				//Revert working directory to previous state
				process.chdir(previousWorkingDirectory);

				var set = migrate();

				set.on('migration', function(migration, direction){
					log(direction, migration.title);
				});

				set.on('save', function(){
					log('migration', 'complete');
					return next();
				});

				set[direction](null, lastMigrationNum);
			});
		});
	}
function performMigration ( direction , migrateTo , next ) { if ( ! next && Object . prototype . toString . call ( migrateTo ) === '[object Function]' ) { next = migrateTo ; migrateTo = undefined ; } if ( ! next ) { next = function ( err ) { if ( err ) { console . error ( err ) ; process . exit ( 1 ) ; } else { process . exit ( ) ; } } } var db = require ( './lib/db' ) ; db . getConnection ( dbConfig || require ( process . cwd ( ) + path . sep + configFileName ) [ dbProperty ] , function ( err , db ) { if ( err ) { return next ( new verror . WError ( err , 'Error connecting to database' ) ) ; } var migrationCollection = db . migrationCollection , dbConnection = db . connection ; migrationCollection . find ( { } ) . sort ( { num : - 1 } ) . limit ( 1 ) . toArray ( function ( err , migrationsRun ) { if ( err ) { return next ( new verror . WError ( err , 'Error querying migration collection' ) ) ; } var lastMigration = migrationsRun [ 0 ] , lastMigrationNum = lastMigration ? lastMigration . num : 0 ; migrate ( { migrationTitle : 'migrations/.migrate' , db : dbConnection , migrationCollection : migrationCollection } ) ; migrations ( direction , lastMigrationNum , migrateTo ) . forEach ( function ( path ) { var mod = require ( process . cwd ( ) + '/' + path ) ; migrate ( { num : parseInt ( path . split ( '/' ) [ 1 ] . match ( / ^(\d+) / ) [ 0 ] , 10 ) , title : path , up : mod . up , down : mod . down } ) ; } ) ; //Revert working directory to previous state process . chdir ( previousWorkingDirectory ) ; var set = migrate ( ) ; set . on ( 'migration' , function ( migration , direction ) { log ( direction , migration . title ) ; } ) ; set . on ( 'save' , function ( ) { log ( 'migration' , 'complete' ) ; return next ( ) ; } ) ; set [ direction ] ( null , lastMigrationNum ) ; } ) ; } ) ; }
Perform a migration in the given `direction`.

@param {String} direction
Perform a migration in the given direction .