diff --git a/lib/sql.js b/lib/sql.js index 1b562a6..e73685f 100644 --- a/lib/sql.js +++ b/lib/sql.js @@ -75,7 +75,7 @@ SQLConnector.prototype.autoupdate = function(models, cb) { models = models || Object.keys(this._models); - async.each(models, function(model, done) { + async.eachSeries(models, function(model, done) { if (!(model in self._models)) { return process.nextTick(function() { done(new Error(g.f('Model not found: %s', model))); @@ -1600,7 +1600,7 @@ SQLConnector.prototype.automigrate = function(models, cb) { }); } - async.each(models, function(model, done) { + async.eachSeries(models, function(model, done) { self.dropTable(model, function(err) { if (err) { // TODO(bajtos) should we abort here and call cb(err)? diff --git a/test/automigrate.test.js b/test/automigrate.test.js index f064ab0..5ecceaf 100644 --- a/test/automigrate.test.js +++ b/test/automigrate.test.js @@ -18,11 +18,13 @@ describe('sql connector', function() { ds.connector._tables = {}; ds.connector._models = {}; ds.createModel('m1', {}); + ds.createModel('m2', {}); }); it('automigrate all models', function(done) { ds.automigrate(function(err) { expect(ds.connector._tables).have.property('m1'); + expect(ds.connector._tables).have.property('m2'); done(err); }); }); @@ -42,10 +44,17 @@ describe('sql connector', function() { }); it('automigrate reports errors for models not attached', function(done) { - ds.automigrate(['m1', 'm2'], function(err) { + ds.automigrate(['m1', 'm3'], function(err) { expect(err).to.be.an.instanceOf(Error); expect(ds.connector._tables).to.not.have.property('m1'); - expect(ds.connector._tables).to.not.have.property('m2'); + expect(ds.connector._tables).to.not.have.property('m3'); + done(); + }); + }); + + it('automigrate tables in series', function(done) { + ds.automigrate(['m1', 'm2'], function(err) { + expect(Object.keys(ds.connector._tables)).to.deep.equal(['m1', 'm2']); done(); }); });