From 1bae8a806218c5c68c7eb8ab801b5675fd4fe732 Mon Sep 17 00:00:00 2001 From: Vincent Giersch Date: Thu, 18 Apr 2013 13:19:59 +0200 Subject: [PATCH 1/2] Handle undefined when altering tables --- lib/mysql.js | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/lib/mysql.js b/lib/mysql.js index b7253c9..335f4dd 100644 --- a/lib/mysql.js +++ b/lib/mysql.js @@ -403,11 +403,13 @@ MySQL.prototype.alterTable = function (model, actualFields, actualIndexes, done, propNames.forEach(function (propName) { if (propName === 'id') return; var found; - actualFields.forEach(function (f) { - if (f.Field === propName) { - found = f; - } - }); + if (actualIndexes) { + actualFields.forEach(function (f) { + if (f.Field === propName) { + found = f; + } + }); + } if (found) { actualize(propName, found); @@ -417,13 +419,15 @@ MySQL.prototype.alterTable = function (model, actualFields, actualIndexes, done, }); // drop columns - actualFields.forEach(function (f) { - var notFound = !~propNames.indexOf(f.Field); - if (f.Field === 'id') return; - if (notFound || !m.properties[f.Field]) { - sql.push('DROP COLUMN `' + f.Field + '`'); - } - }); + if (actualFields) { + actualFields.forEach(function (f) { + var notFound = !~propNames.indexOf(f.Field); + if (f.Field === 'id') return; + if (notFound || !m.properties[f.Field]) { + sql.push('DROP COLUMN `' + f.Field + '`'); + } + }); + } // remove indexes aiNames.forEach(function (indexName) { From fa617dc35fa25570a8871ff03f47cc3f905d3d52 Mon Sep 17 00:00:00 2001 From: Vincent Giersch Date: Thu, 18 Apr 2013 15:57:56 +0200 Subject: [PATCH 2/2] Mistake in an undefined check --- lib/mysql.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/mysql.js b/lib/mysql.js index 335f4dd..c34c026 100644 --- a/lib/mysql.js +++ b/lib/mysql.js @@ -403,7 +403,7 @@ MySQL.prototype.alterTable = function (model, actualFields, actualIndexes, done, propNames.forEach(function (propName) { if (propName === 'id') return; var found; - if (actualIndexes) { + if (actualFields) { actualFields.forEach(function (f) { if (f.Field === propName) { found = f;