From 04c10fdf03a95b65c4179f0b4c84f980e4e9a09a Mon Sep 17 00:00:00 2001 From: Raymond Feng Date: Thu, 11 Sep 2014 12:23:32 -0700 Subject: [PATCH] Enhance error reporting for automigrate/autoupdate --- lib/mysql.js | 25 ++++++++++++++----------- package.json | 6 +++--- test/migration.test.js | 12 ++++++++++++ 3 files changed, 29 insertions(+), 14 deletions(-) diff --git a/lib/mysql.js b/lib/mysql.js index 5c8b2c4..4bd4b55 100644 --- a/lib/mysql.js +++ b/lib/mysql.js @@ -650,19 +650,22 @@ MySQL.prototype.autoupdate = function (models, cb) { models = models || Object.keys(this._models); - async.each(models, function (model, done) { - if (model in self._models) { - var table = self.tableEscaped(model); - self.query('SHOW FIELDS FROM ' + table, function (err, fields) { - self.query('SHOW INDEXES FROM ' + table, function (err, indexes) { - if (!err && fields && fields.length) { - self.alterTable(model, fields, indexes, done); - } else { - self.createTable(model, done); - } - }); + async.each(models, function(model, done) { + if (!(model in self._models)) { + return process.nextTick(function() { + done(new Error('Model not found: ' + model)); }); } + var table = self.tableEscaped(model); + self.query('SHOW FIELDS FROM ' + table, function(err, fields) { + self.query('SHOW INDEXES FROM ' + table, function(err, indexes) { + if (!err && fields && fields.length) { + self.alterTable(model, fields, indexes, done); + } else { + self.createTable(model, done); + } + }); + }); }, cb); }; diff --git a/package.json b/package.json index 1aaab2d..c1502b7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "loopback-connector-mysql", - "version": "1.4.6", + "version": "1.4.7", "description": "MySQL connector for loopback-datasource-juggler", "main": "index.js", "scripts": { @@ -8,9 +8,9 @@ }, "dependencies": { "loopback-connector": "1.x", - "mysql": "~2.3.2", + "mysql": "~2.5.0", "async": "~0.9.0", - "debug": "~1.0.2" + "debug": "~2.0.0" }, "devDependencies": { "loopback-datasource-juggler": "1.x.x", diff --git a/test/migration.test.js b/test/migration.test.js index b23c5e6..ce35c69 100644 --- a/test/migration.test.js +++ b/test/migration.test.js @@ -304,6 +304,18 @@ describe('migrations', function () { }); }); + it('should report errors for automigrate', function() { + db.automigrate('XYZ', function(err) { + assert(err); + }); + }); + + it('should report errors for autoupdate', function() { + db.autoupdate('XYZ', function(err) { + assert(err); + }); + }); + it('should disconnect when done', function (done) { db.disconnect(); done();