Merge pull request #170 from klassicd/issue-168
fix: run migrations in series
This commit is contained in:
commit
49e4c37ba7
|
@ -75,7 +75,7 @@ SQLConnector.prototype.autoupdate = function(models, cb) {
|
||||||
|
|
||||||
models = models || Object.keys(this._models);
|
models = models || Object.keys(this._models);
|
||||||
|
|
||||||
async.each(models, function(model, done) {
|
async.eachSeries(models, function(model, done) {
|
||||||
if (!(model in self._models)) {
|
if (!(model in self._models)) {
|
||||||
return process.nextTick(function() {
|
return process.nextTick(function() {
|
||||||
done(new Error(g.f('Model not found: %s', model)));
|
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) {
|
self.dropTable(model, function(err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
// TODO(bajtos) should we abort here and call cb(err)?
|
// TODO(bajtos) should we abort here and call cb(err)?
|
||||||
|
|
|
@ -18,11 +18,13 @@ describe('sql connector', function() {
|
||||||
ds.connector._tables = {};
|
ds.connector._tables = {};
|
||||||
ds.connector._models = {};
|
ds.connector._models = {};
|
||||||
ds.createModel('m1', {});
|
ds.createModel('m1', {});
|
||||||
|
ds.createModel('m2', {});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('automigrate all models', function(done) {
|
it('automigrate all models', function(done) {
|
||||||
ds.automigrate(function(err) {
|
ds.automigrate(function(err) {
|
||||||
expect(ds.connector._tables).have.property('m1');
|
expect(ds.connector._tables).have.property('m1');
|
||||||
|
expect(ds.connector._tables).have.property('m2');
|
||||||
done(err);
|
done(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -42,10 +44,17 @@ describe('sql connector', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('automigrate reports errors for models not attached', function(done) {
|
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(err).to.be.an.instanceOf(Error);
|
||||||
expect(ds.connector._tables).to.not.have.property('m1');
|
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();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue