Merge pull request #170 from klassicd/issue-168

fix: run migrations in series
This commit is contained in:
Diana Lau 2020-04-01 10:15:07 -04:00 committed by GitHub
commit 49e4c37ba7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 4 deletions

View File

@ -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)?

View File

@ -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();
});
});