Skip to content

Commit

Permalink
Add callback to run
Browse files Browse the repository at this point in the history
  • Loading branch information
cellis committed Feb 11, 2018
1 parent eb93c75 commit 260becf
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
4 changes: 2 additions & 2 deletions api.js
Original file line number Diff line number Diff line change
Expand Up @@ -435,8 +435,8 @@ dbmigrate.prototype = {
/**
* Executes the default routine.
*/
run: function () {
load('run')(this.internals, this.config);
run: function (callback) {
load('run')(this.internals, this.config, callback);
}
};

Expand Down
27 changes: 16 additions & 11 deletions lib/commands/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ var log = require('db-migrate-shared').log;
var optimist = require('optimist');
var load = require('./');
var transition = load('transition');
Promise = require('bluebird');

function run (internals, config) {
function run (internals, config, callback) {
var action = internals.argv._.shift();
var folder = action.split(':');

action = folder[0];
var toExecute = null;

switch (action) {
case 'transition':
Expand All @@ -20,10 +22,10 @@ function run (internals, config) {
internals.matching = folder[1];
internals.migrationMode = folder[1];
}
load('create-migration')(internals, config);
toExecute = load('create-migration');
break;
case 'sync':
var executeSync = load('sync');
toExecute = load('sync');

if (internals.argv._.length === 0) {
log.error('Missing sync destination!');
Expand All @@ -38,7 +40,6 @@ function run (internals, config) {
internals.migrationMode = folder[1];
}

executeSync(internals, config);
break;
case 'up':
case 'down':
Expand All @@ -60,11 +61,9 @@ function run (internals, config) {
}

if (action === 'up') {
var executeUp = load('up');
executeUp(internals, config);
toExecute = load('up');
} else {
var executeDown = load('down');
executeDown(internals, config);
toExecute = load('down');
}
break;

Expand All @@ -73,7 +72,7 @@ function run (internals, config) {
log.info('Please enter a valid command, i.e. db:create|db:drop');
} else {
internals.mode = folder[1];
load('db')(internals, config);
toExecute = load('db');
}
break;
case 'seed':
Expand All @@ -86,9 +85,9 @@ function run (internals, config) {
}

internals.argv._.shift();
load('undo-seed')(internals, config);
toExecute = load('undo-seed');
} else {
load('seed')(internals, config);
toExecute = load('seed');
}
break;

Expand All @@ -112,6 +111,12 @@ function run (internals, config) {
}
break;
}

if (toExecute) {
toExecute(internals, config, callback);
} else {
callback();
}
}

module.exports = run;

0 comments on commit 260becf

Please sign in to comment.