Handle undefined when altering tables

This commit is contained in:
Vincent Giersch 2013-04-18 13:19:59 +02:00
parent 5f007eabc0
commit 1bae8a8062
1 changed files with 16 additions and 12 deletions

View File

@ -403,11 +403,13 @@ MySQL.prototype.alterTable = function (model, actualFields, actualIndexes, done,
propNames.forEach(function (propName) { propNames.forEach(function (propName) {
if (propName === 'id') return; if (propName === 'id') return;
var found; var found;
actualFields.forEach(function (f) { if (actualIndexes) {
if (f.Field === propName) { actualFields.forEach(function (f) {
found = f; if (f.Field === propName) {
} found = f;
}); }
});
}
if (found) { if (found) {
actualize(propName, found); actualize(propName, found);
@ -417,13 +419,15 @@ MySQL.prototype.alterTable = function (model, actualFields, actualIndexes, done,
}); });
// drop columns // drop columns
actualFields.forEach(function (f) { if (actualFields) {
var notFound = !~propNames.indexOf(f.Field); actualFields.forEach(function (f) {
if (f.Field === 'id') return; var notFound = !~propNames.indexOf(f.Field);
if (notFound || !m.properties[f.Field]) { if (f.Field === 'id') return;
sql.push('DROP COLUMN `' + f.Field + '`'); if (notFound || !m.properties[f.Field]) {
} sql.push('DROP COLUMN `' + f.Field + '`');
}); }
});
}
// remove indexes // remove indexes
aiNames.forEach(function (indexName) { aiNames.forEach(function (indexName) {