-
Notifications
You must be signed in to change notification settings - Fork 24
Description
I've tried using mongration but found I wanted my steps to be able to use the winston logger module. When doing things programatically, where you initialise your migration from our own top level .js file, you provide mongration with where to find your steps, then it instantiates and runs them completely out of your control.
I think other users may have all sorts of other similar requirements to pass in custom objects or config to their steps, that were constructed in the main .js file. In my case, this looked like this:
'use strict';
var path = require('path'),
Migration = require('mongration').Migration,
winston = require('winston');
var config = {
hosts: 'localhost',
db: 'WIN',
migrationCollection: 'ratesMigration',
stepConfig: { // <-- this stepConfig argument is new
log: winston
}
}, log = winston;
winston.level = 'debug';
var migration = new Migration(config);
migration.addAllFromPath(path.join(__dirname, './migration-steps/'));
migration.migrate(function(err, results){
log.error(err, results);
});
My Step wants to use it like this:
up: function (db, cb) {
this.config.log.debug('up has started.');
}
The winston logger instantiated in the top level code may have all sorts of appenders added (file, database, Amazon SNS, whatever) and the steps should each log to the same log stream. Other users requirements may vary.