Merge branch 'release/1.4.6' into production

This commit is contained in:
Raymond Feng 2014-09-10 23:46:57 -07:00
commit e827c14189
2 changed files with 26 additions and 32 deletions

View File

@ -6,6 +6,7 @@ var mysql = require('mysql');
var SqlConnector = require('loopback-connector').SqlConnector;
var EnumFactory = require('./enumFactory').EnumFactory;
var async = require('async');
var debug = require('debug')('loopback:connector:mysql');
/**
@ -637,7 +638,7 @@ MySQL.prototype.destroyAll = function destroyAll(model, where, callback) {
*/
MySQL.prototype.autoupdate = function (models, cb) {
var self = this;
var wait = 0;
if ((!cb) && ('function' === typeof models)) {
cb = models;
models = undefined;
@ -649,11 +650,11 @@ MySQL.prototype.autoupdate = function (models, cb) {
models = models || Object.keys(this._models);
models.forEach(function (model) {
async.each(models, function (model, done) {
if (model in self._models) {
wait++;
self.query('SHOW FIELDS FROM ' + self.tableEscaped(model), function (err, fields) {
self.query('SHOW INDEXES FROM ' + self.tableEscaped(model), function (err, indexes) {
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 {
@ -662,16 +663,8 @@ MySQL.prototype.autoupdate = function (models, cb) {
});
});
}
});
}, cb);
function done(err) {
if (err) {
console.error('%j', err);
}
if (--wait === 0 && cb) {
cb();
}
}
};
/*!
@ -695,28 +688,29 @@ MySQL.prototype.createTable = function (model, cb) {
* @param {String[]} [models] A model name or an array of model names. If not present, apply to all models
* @param {Function} [cb] The callback function
*/
MySQL.prototype.isActual = function (cb) {
var ok = false;
MySQL.prototype.isActual = function(cb) {
var self = this;
var wait = 0;
Object.keys(this._models).forEach(function (model) {
wait += 1;
self.query('SHOW FIELDS FROM ' + model, function (err, fields) {
self.query('SHOW INDEXES FROM ' + model, function (err, indexes) {
self.alterTable(model, fields, indexes, done, true);
var ok = false;
async.each(Object.keys(this._models), function(model, done) {
var table = self.tableEscaped(model);
self.query('SHOW FIELDS FROM ' + table, function(err, fields) {
self.query('SHOW INDEXES FROM ' + table, function(err, indexes) {
self.alterTable(model, fields, indexes, function(err, needAlter) {
if (err) {
return done(err);
} else {
ok = ok || needAlter;
done(err);
}
}, true);
});
});
});
function done(err, needAlter) {
}, function(err) {
if (err) {
debug(err);
return err;
}
ok = ok || needAlter;
if (--wait === 0 && cb) {
cb(null, !ok);
}
}
cb(null, !ok);
});
};
MySQL.prototype.alterTable = function (model, actualFields, actualIndexes, done, checkOnly) {

View File

@ -1,6 +1,6 @@
{
"name": "loopback-connector-mysql",
"version": "1.4.5",
"version": "1.4.6",
"description": "MySQL connector for loopback-datasource-juggler",
"main": "index.js",
"scripts": {