Skip to content

Commit

Permalink
improved error handling of seeders
Browse files Browse the repository at this point in the history
  • Loading branch information
wzrdtales committed May 9, 2015
1 parent c46192c commit 731e2c6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
1 change: 1 addition & 0 deletions api.js
Expand Up @@ -43,6 +43,7 @@ function dbmigrate(isModule, callback) {
internals.dbm = dbm;
global.dbm = dbm; //deprecated
internals.migrationOptions = { dbmigrate: internals.dbm };
internals.seederOptions = { dbmigrate: internals.dbm };
}


Expand Down
32 changes: 22 additions & 10 deletions lib/seeder.js
Expand Up @@ -118,14 +118,20 @@ Seeder.prototype = {
log.verbose('preparing to run up seeder:', seeder.name);

return self.driver.startMigration()
.catch(callback)
.then(function() {
var setup = seeder.setup();

if(typeof(setup) === 'function')
setup(internals.seederOptions);

return (Promise.promisify(self.up.bind(self)))(seeder.up.bind(seeder));
});
})
.then(self.driver.endMigration.bind(self.driver));
})
.catch(function(e) {

throw e;
})
.catch(callback)
.then(self.driver.endMigration.bind(self.driver))
.catch(callback)
.nodeify(callback);

});
Expand All @@ -150,15 +156,21 @@ Seeder.prototype = {
log.verbose('preparing to run down seeder:', seeder.name);

return self.driver.startMigration()
.catch(callback)
.then(function() {

var setup = seeder.setup();

if(typeof(setup) === 'function')
setup(internals.seederOptions);

return (Promise.promisify(self.down.bind(self)))(seeder.down.bind(seeder));
});
})
.then(self.driver.endMigration.bind(self.driver));

})
.catch(callback)
.then(self.driver.endMigration.bind(self.driver))
.catch(callback)
.catch(function(e) {
throw e;
})
.nodeify(callback);
});
}
Expand Down

0 comments on commit 731e2c6

Please sign in to comment.