Skip to content

Commit

Permalink
Do not have multiple migration calls completing same callback
Browse files Browse the repository at this point in the history
  • Loading branch information
ivaosthu committed Feb 22, 2017
1 parent fc5abb2 commit 8c0410c
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions migrations/20170211090541-add-default-strategies.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ function removeStrategySQL (strategy) {

exports.up = function (db, callback) {
const insertStrategies = strategies.map((s) => (cb) => {
db.runSql(insertEventsSQL(s), cb);
db.runSql(insertStrategySQL(s), cb);
async.series([
db.runSql.bind(db, insertEventsSQL(s)),
db.runSql.bind(db, insertStrategySQL(s)),
], cb);
});
async.series(insertStrategies, callback);
};
Expand All @@ -51,8 +53,10 @@ exports.down = function (db, callback) {
const removeStrategies = strategies
.filter(s => s.name !== 'default')
.map((s) => (cb) => {
db.runSql(removeEventsSQL(s), cb);
db.runSql(removeStrategySQL(s), cb);
async.series([
db.runSql.bind(db, removeEventsSQL(s)),
db.runSql.bind(db, removeStrategySQL(s)),
], cb);
});

async.series(removeStrategies, callback);
Expand Down

2 comments on commit 8c0410c

@sveisvei
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 lets hope this works :)

@ivarconr
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does, I was able to reproduce it locally by changing async version. (Async was not declared as a specific dependency.)

Please sign in to comment.