mongoose-migrate icon indicating copy to clipboard operation
mongoose-migrate copied to clipboard

Allow migrations to return a promise

Open jordonbiondo opened this issue 10 years ago • 0 comments

I find it preferably to work with promises over callbacks, it would be nice to have the option to return promises instead of ending all my promise chains with .then(() => next(); next)

Mocha has a nice feature where it looks at the .length of the function given and if it equals 0, then it expects the function to return a promise. If the function takes an argument, it assumes the argument to provide the callback fn.

Meaning that these two migrations would effectively be the same:

exports.up = function () { return Promise.resolve(); }

exports.up = function(next) { next(); }

If possible, I think this would be a great addition to mongoose-migrations and I would be interested in supplying a PR for it if requested.

jordonbiondo avatar Dec 07 '15 21:12 jordonbiondo