From b00f456721e5db9991817bd54bc3762f28b1802d Mon Sep 17 00:00:00 2001 From: Sebastian Van Sande Date: Fri, 10 Feb 2017 15:59:25 +0100 Subject: [PATCH] cleanups --- .travis.yml | 7 +++--- bin/migrate-mongo.js | 51 ++++++++++++++++++------------------------- lib/actions/create.js | 2 +- lib/actions/down.js | 5 +---- lib/actions/status.js | 4 ++-- lib/actions/up.js | 5 +---- 6 files changed, 29 insertions(+), 45 deletions(-) diff --git a/.travis.yml b/.travis.yml index 2d3fd99..4656d2e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,7 @@ language: node_js node_js: - - "4.7.2" - - "6.9.4" - - "7.4.0" + - "4.7.3" + - "6.9.5" + - "7.5.0" script: "npm run-script test-coverage" -# Send coverage data to Coveralls after_script: "cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js" diff --git a/bin/migrate-mongo.js b/bin/migrate-mongo.js index 85e5c78..ebf5c7c 100755 --- a/bin/migrate-mongo.js +++ b/bin/migrate-mongo.js @@ -1,17 +1,16 @@ #! /usr/bin/env node -var program = require('commander'); -var _ = require('lodash'); -var migrateMongo = require('../lib/migrate-mongo'); -var database = require('../lib/env/database'); - -var Table = require('cli-table'); +const program = require('commander'); +const _ = require('lodash'); +const Table = require('cli-table'); +const migrateMongo = require('../lib/migrate-mongo'); +const database = require('../lib/env/database'); program .command('init') .description('initialize a new migration project') .action(function () { - migrateMongo.init(function (err) { + migrateMongo.init((err) => { if (err) return handleError(err); console.log('Initialization successful. Please edit the generated config.js file'); }); @@ -20,8 +19,8 @@ program program .command('create [description]') .description('create a new database migration with the provided description') - .action(function (description) { - migrateMongo.create(description, function (err, filename) { + .action((description) =>{ + migrateMongo.create(description, (err, filename) => { if (err) return handleError(err); console.log('Created: migrations/' + filename); }); @@ -31,15 +30,12 @@ program .command('up') .description('run all unapplied database migrations') .option('-f --file ', 'use a custom config file') - .action(function (options) { + .action((options) =>{ global.options = options; - database.connect(function (err, db) { + database.connect((err, db) => { if (err) return handleError(err); - migrateMongo.up(db, function (err, migrated) { - migrated.forEach(function (migratedItem) { - console.log('MIGRATED UP: ' + migratedItem); - }); - + migrateMongo.up(db, (err, migrated) => { + migrated.forEach((migratedItem) => console.log(`MIGRATED UP: ${migratedItem}`)); if (err) return handleError(err); process.exit(0); }); @@ -50,15 +46,12 @@ program .command('down') .description('undo the last applied database migration') .option('-f --file ', 'use a custom config file') - .action(function (options) { + .action((options) => { global.options = options; - database.connect(function (err, db) { + database.connect((err, db) => { if (err) return handleError(err); - migrateMongo.down(db, function (err, migrated) { - migrated.forEach(function (migratedItem) { - console.log('MIGRATED DOWN: ' + migratedItem); - }); - + migrateMongo.down(db, (err, migrated) => { + migrated.forEach(migratedItem => console.log('MIGRATED DOWN: ' + migratedItem)); if (err) return handleError(err); process.exit(0); }); @@ -69,11 +62,11 @@ program .command('status') .description('print the changelog of the database') .option('-f --file ', 'use a custom config file') - .action(function (options) { + .action((options) => { global.options = options; - database.connect(function (err, db) { + database.connect((err, db) => { if (err) return handleError(err); - migrateMongo.status(db, function (err, statusItems) { + migrateMongo.status(db, (err, statusItems) => { if (err) return handleError(err); printStatusTable(statusItems); process.exit(0); @@ -93,9 +86,7 @@ function handleError(err) { } function printStatusTable(statusItems) { - var table = new Table({head: ['Filename', 'Applied At']}); - statusItems.forEach(function (item) { - table.push(_.values(item)); - }); + const table = new Table({head: ['Filename', 'Applied At']}); + statusItems.forEach(item => table.push(_.values(item))); console.log(table.toString()); } \ No newline at end of file diff --git a/lib/actions/create.js b/lib/actions/create.js index a1bba6f..048460b 100644 --- a/lib/actions/create.js +++ b/lib/actions/create.js @@ -12,7 +12,7 @@ module.exports = function (description, done) { async.waterfall([ migrationsDir.shouldExist, (taskDone) => { - description = description.split(' ').join('_'); // replace spaces with underscores + description = description.split(' ').join('_'); const source = path.join(__dirname, '../../samples/migration.js'); const filename = moment.utc().format('YYYYMMDDHHmmss') + '-' + description + '.js'; const destination = path.join(process.cwd(), 'migrations', filename); diff --git a/lib/actions/down.js b/lib/actions/down.js index 7fc175c..36e8531 100644 --- a/lib/actions/down.js +++ b/lib/actions/down.js @@ -37,8 +37,5 @@ module.exports = function (db, done) { }); }); } - ], function (err) { - if (err) return done(err, downgraded); - return done(null, downgraded); - }); + ], (err) => done(err, downgraded)); }; \ No newline at end of file diff --git a/lib/actions/status.js b/lib/actions/status.js index e039c38..8a2c338 100644 --- a/lib/actions/status.js +++ b/lib/actions/status.js @@ -23,7 +23,7 @@ module.exports = function (db, done) { function fetchContentOfChangeLog(next) { const collectionName = configFile.read().changelogCollectionName; const collection = db.collection(collectionName); - collection.find({}).toArray(function (err, docs) { + collection.find({}).toArray((err, docs) => { if (err) return next(err); context.changelog = docs; next(); @@ -33,7 +33,7 @@ module.exports = function (db, done) { if (err) return done(err); const statusTable = context.fileNames.map((fileName) => { const itemInLog = _.find(context.changelog, {fileName}); - const appliedAt = (itemInLog) ? itemInLog.appliedAt.toJSON() : 'PENDING'; + const appliedAt = itemInLog ? itemInLog.appliedAt.toJSON() : 'PENDING'; return { fileName, appliedAt }; }); return done(null, statusTable); diff --git a/lib/actions/up.js b/lib/actions/up.js index 9874905..6251366 100644 --- a/lib/actions/up.js +++ b/lib/actions/up.js @@ -35,8 +35,5 @@ module.exports = function (db, done) { }); }, next); } - ], (err) => { - if (err) return done(err, upgraded); - return done(null, upgraded); - }); + ], (err) => done(err, upgraded)); }; \ No newline at end of file