From ceeffd414399525b3bccfe818a0cd8220dfdf6d0 Mon Sep 17 00:00:00 2001 From: Ives De Bruycker Date: Wed, 10 Jan 2018 10:45:53 +0100 Subject: [PATCH] feat: Migrate up/down with cli --- bin/cli | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/bin/cli b/bin/cli index 07f0114..2042647 100755 --- a/bin/cli +++ b/bin/cli @@ -76,9 +76,19 @@ program .alias('up') .description('Migrate to the given migration') .action(function(to, options){ - console.log('Migrating up to: "%s" [TODO]', to); + console.log('Migrating up to: "%s"', to); var server = program.server || process.cwd() + '/server/server.js'; var app = require(path.resolve(process.cwd(), server)); + app.models.Migration.migrate('up', to) + .then(function (res) { + console.log('Done.'); + }) + .catch(function (err) { + console.log(err); + }) + .finally(function () { + process.exit(); + }); }).on('--help', function() { console.log(' Examples:'); console.log(); @@ -92,9 +102,19 @@ program .alias('down') .description('Rollback to the given migration') .action(function(to, options){ - console.log('Rolling back to: "%s" [TODO]', to); + console.log('Rolling back to: "%s"', to); var server = program.server || process.cwd() + '/server/server.js'; var app = require(path.resolve(process.cwd(), server)); + app.models.Migration.migrate('down', to) + .then(function (res) { + console.log('Done.'); + }) + .catch(function (err) { + console.log(err); + }) + .finally(function () { + process.exit(); + }); }).on('--help', function() { console.log(' Examples:'); console.log();