Skip to content

Commit

Permalink
cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
seppevs committed Feb 10, 2017
1 parent 8fc47fd commit b00f456
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 45 deletions.
7 changes: 3 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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"
51 changes: 21 additions & 30 deletions bin/migrate-mongo.js
Original file line number Diff line number Diff line change
@@ -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');
});
Expand All @@ -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);
});
Expand All @@ -31,15 +30,12 @@ program
.command('up')
.description('run all unapplied database migrations')
.option('-f --file <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);
});
Expand All @@ -50,15 +46,12 @@ program
.command('down')
.description('undo the last applied database migration')
.option('-f --file <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);
});
Expand All @@ -69,11 +62,11 @@ program
.command('status')
.description('print the changelog of the database')
.option('-f --file <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);
Expand All @@ -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());
}
2 changes: 1 addition & 1 deletion lib/actions/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 1 addition & 4 deletions lib/actions/down.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
};
4 changes: 2 additions & 2 deletions lib/actions/status.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
Expand Down
5 changes: 1 addition & 4 deletions lib/actions/up.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
};

0 comments on commit b00f456

Please sign in to comment.