-
-
Notifications
You must be signed in to change notification settings - Fork 359
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add callback to run #547
Add callback to run #547
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. never require as global |
||
|
||
function run (internals, config) { | ||
function run (internals, config, callback) { | ||
var action = internals.argv._.shift(); | ||
var folder = action.split(':'); | ||
|
||
action = folder[0]; | ||
var toExecute = null; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. always move definitions to the top of the current scope There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also do not initialize something with |
||
|
||
switch (action) { | ||
case 'transition': | ||
|
@@ -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!'); | ||
|
@@ -38,7 +40,6 @@ function run (internals, config) { | |
internals.migrationMode = folder[1]; | ||
} | ||
|
||
executeSync(internals, config); | ||
break; | ||
case 'up': | ||
case 'down': | ||
|
@@ -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; | ||
|
||
|
@@ -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': | ||
|
@@ -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; | ||
|
||
|
@@ -112,6 +111,12 @@ function run (internals, config) { | |
} | ||
break; | ||
} | ||
|
||
if (toExecute) { | ||
toExecute(internals, config, callback); | ||
} else { | ||
callback(); | ||
} | ||
} | ||
|
||
module.exports = run; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not a valid definition, everything needs to be a promise in the first place. callbacks are just second class citizens and just supported for backwards compatibility.