From 78476b5a9ac1fbcdce43ce704454c3145af434fe Mon Sep 17 00:00:00 2001 From: Serkan Serttop Date: Sun, 30 Nov 2014 02:40:41 +0200 Subject: [PATCH 1/8] Inherit Schema From DataSource if not defined If owner is not set via json in the discovery process, use the database schema defined in the dataSource setting. --- lib/discovery.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/lib/discovery.js b/lib/discovery.js index 087cbab..43701c0 100644 --- a/lib/discovery.js +++ b/lib/discovery.js @@ -167,6 +167,9 @@ function mixinDiscovery(MySQL) { MySQL.prototype.discoverModelProperties = function (table, options, cb) { var args = getArgs(table, options, cb); var owner = args.owner; + if(!owner){ + owner = inheritOwnerViaDataSource.call(this); + } table = args.table; options = args.options; cb = args.cb; @@ -217,6 +220,9 @@ function mixinDiscovery(MySQL) { MySQL.prototype.discoverPrimaryKeys = function (table, options, cb) { var args = getArgs(table, options, cb); var owner = args.owner; + if(!owner){ + owner = inheritOwnerViaDataSource.call(this); + } table = args.table; options = args.options; cb = args.cb; @@ -258,6 +264,9 @@ function mixinDiscovery(MySQL) { MySQL.prototype.discoverForeignKeys = function (table, options, cb) { var args = getArgs(table, options, cb); var owner = args.owner; + if(!owner){ + owner = inheritOwnerViaDataSource.call(this); + } table = args.table; options = args.options; cb = args.cb; @@ -301,6 +310,9 @@ function mixinDiscovery(MySQL) { MySQL.prototype.discoverExportedForeignKeys = function (table, options, cb) { var args = getArgs(table, options, cb); var owner = args.owner; + if(!owner){ + owner = inheritOwnerViaDataSource.call(this); + } table = args.table; options = args.options; cb = args.cb; @@ -355,4 +367,11 @@ function mixinDiscovery(MySQL) { return 'String'; } } + + function inheritOwnerViaDataSource(){ + if(this.dataSource && this.dataSource.settings && this.dataSource.settings.database){ + return this.dataSource.settings.database; + } + return undefined; + } } From e00b0ba8cf78e862c4467bc0cd0660cc34003184 Mon Sep 17 00:00:00 2001 From: Geoffroy Lesage Date: Tue, 23 Dec 2014 04:06:24 -0600 Subject: [PATCH 2/8] Fixed isActual implemenation --- lib/mysql.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/mysql.js b/lib/mysql.js index 3390a56..4dde58e 100644 --- a/lib/mysql.js +++ b/lib/mysql.js @@ -691,10 +691,10 @@ 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) { +MySQL.prototype.isActual = function(models, cb) { var self = this; var ok = false; - async.each(Object.keys(this._models), function(model, done) { + async.each(Object.keys(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) { From 9d3ab6fc42b8d43f7c01a229279666f95aa4b3b1 Mon Sep 17 00:00:00 2001 From: Geoffroy Lesage Date: Thu, 8 Jan 2015 10:29:55 -0600 Subject: [PATCH 3/8] Fixed isActual syntax to accept optional model arg --- lib/mysql.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/mysql.js b/lib/mysql.js index 4dde58e..a9c32fe 100644 --- a/lib/mysql.js +++ b/lib/mysql.js @@ -693,7 +693,18 @@ MySQL.prototype.createTable = function (model, cb) { */ MySQL.prototype.isActual = function(models, cb) { var self = this; - var ok = false; + + if ((!cb) && ('function' === typeof models)) { + cb = models; + models = undefined; + } + // First argument is a model name + if ('string' === typeof models) { + models = [models]; + } + + models = models || Object.keys(this._models); + async.each(Object.keys(models), function(model, done) { var table = self.tableEscaped(model); self.query('SHOW FIELDS FROM ' + table, function(err, fields) { From bc2dc4e6a221f1321d91539887ff1aaba6f2e490 Mon Sep 17 00:00:00 2001 From: Geoffroy Lesage Date: Thu, 15 Jan 2015 15:59:50 -0600 Subject: [PATCH 4/8] Changed default type mapping --- lib/mysql.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/mysql.js b/lib/mysql.js index 17cbabe..928bab3 100644 --- a/lib/mysql.js +++ b/lib/mysql.js @@ -1036,10 +1036,6 @@ function datatype(p) { var dt = ''; switch (p.type.name) { default: - case 'String': - dt = columnType(p, 'VARCHAR'); - dt = stringOptionsByType(p, dt); - break; case 'JSON': case 'Object': case 'Any': @@ -1047,6 +1043,10 @@ function datatype(p) { dt = columnType(p, 'TEXT'); dt = stringOptionsByType(p, dt); break; + case 'String': + dt = columnType(p, 'VARCHAR'); + dt = stringOptionsByType(p, dt); + break; case 'Number': dt = columnType(p, 'INT'); dt = numericOptionsByType(p, dt); From 0511830a12db61c6abc0756233c253ab7b9e05f4 Mon Sep 17 00:00:00 2001 From: Geoffroy Lesage Date: Thu, 15 Jan 2015 16:08:41 -0600 Subject: [PATCH 5/8] Fixed missing 'ok' --- lib/mysql.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/mysql.js b/lib/mysql.js index 17cbabe..109b03c 100644 --- a/lib/mysql.js +++ b/lib/mysql.js @@ -692,6 +692,7 @@ MySQL.prototype.createTable = function (model, cb) { */ MySQL.prototype.isActual = function(models, cb) { var self = this; + var ok; if ((!cb) && ('function' === typeof models)) { cb = models; From 07722239082cb68a278456750ecc97d23e9f4937 Mon Sep 17 00:00:00 2001 From: Geoffroy Lesage Date: Thu, 15 Jan 2015 16:09:47 -0600 Subject: [PATCH 6/8] Set ok default to false --- lib/mysql.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/mysql.js b/lib/mysql.js index 109b03c..19118b9 100644 --- a/lib/mysql.js +++ b/lib/mysql.js @@ -692,7 +692,7 @@ MySQL.prototype.createTable = function (model, cb) { */ MySQL.prototype.isActual = function(models, cb) { var self = this; - var ok; + var ok = false; if ((!cb) && ('function' === typeof models)) { cb = models; From 8b860890e8e22f36fad5a5db9a773fd8911a26db Mon Sep 17 00:00:00 2001 From: Raymond Feng Date: Thu, 15 Jan 2015 14:21:49 -0800 Subject: [PATCH 7/8] Fix the loop of models --- lib/mysql.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/mysql.js b/lib/mysql.js index 2143857..38d76aa 100644 --- a/lib/mysql.js +++ b/lib/mysql.js @@ -705,7 +705,7 @@ MySQL.prototype.isActual = function(models, cb) { models = models || Object.keys(this._models); - async.each(Object.keys(models), function(model, done) { + async.each(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) { From 4c46c6af2fc92e14c47677aafbdff609ff2095ab Mon Sep 17 00:00:00 2001 From: Raymond Feng Date: Thu, 15 Jan 2015 14:33:09 -0800 Subject: [PATCH 8/8] v1.5.1 --- CHANGES.md | 18 ++++++++++++++++++ package.json | 4 ++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 0ea866a..c7ad001 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,21 @@ +2015-01-15, Version 1.5.1 +========================= + + * Fix the loop of models (Raymond Feng) + + * Set ok default to false (Geoffroy Lesage) + + * Fixed missing 'ok' (Geoffroy Lesage) + + * Changed default type mapping (Geoffroy Lesage) + + * Fixed isActual syntax to accept optional model arg (Geoffroy Lesage) + + * Fixed isActual implemenation (Geoffroy Lesage) + + * Inherit Schema From DataSource if not defined (Serkan Serttop) + + 2015-01-09, Version 1.5.0 ========================= diff --git a/package.json b/package.json index 68688cc..5423c8c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "loopback-connector-mysql", - "version": "1.5.0", + "version": "1.5.1", "description": "MySQL connector for loopback-datasource-juggler", "main": "index.js", "scripts": { @@ -27,6 +27,6 @@ "url": "https://github.com/strongloop/loopback-connector-mysql/blob/master/LICENSE" }, "optionalDependencies": { - "sl-blip": "http://blip.strongloop.com/loopback-connector-mysql@1.5.0" + "sl-blip": "http://blip.strongloop.com/loopback-connector-mysql@1.5.1" } }