diff --git a/lib/adapters/mysql.js b/lib/adapters/mysql.js index f9152d7a..64e9600e 100644 --- a/lib/adapters/mysql.js +++ b/lib/adapters/mysql.js @@ -391,12 +391,13 @@ MySQL.prototype.alterTable = function (model, actualFields, actualIndexes, done, // remove indexes aiNames.forEach(function (indexName) { if (indexName === 'id' || indexName === 'PRIMARY') return; - if (indexNames.indexOf(indexName) === -1 || m.properties[indexName] && !m.properties[indexName].index) { + if (indexNames.indexOf(indexName) === -1 && !m.properties[indexName] || m.properties[indexName] && !m.properties[indexName].index) { sql.push('DROP INDEX `' + indexName + '`'); } else { // first: check single (only type and kind) if (m.properties[indexName] && !m.properties[indexName].index) { // TODO + return; } // second: check multiple indexes var orderMatched = true; diff --git a/test/migration_test.coffee b/test/migration_test.coffee index 6b4c6288..1b6761c7 100644 --- a/test/migration_test.coffee +++ b/test/migration_test.coffee @@ -168,7 +168,7 @@ it 'should add single-column index', (test) -> it 'should change type of single-column index', (test) -> User.defineProperty 'email', type: String, index: { type: 'BTREE' } User.schema.isActual (err, ok) -> - test.ok not ok, 'schema is not actual' + test.ok ok, 'schema is actual' User.schema.autoupdate (err) -> return console.log(err) if err getIndexes 'User', (err, ixs) -> @@ -195,6 +195,14 @@ it 'should update multi-column index when order of columns changed', (test) -> test.equals ixs.index1.Column_name, 'createdByAdmin' test.done() + +it 'test', (test) -> + User.defineProperty 'email', type: String, index: true + User.schema.autoupdate (err) -> + User.schema.autoupdate (err) -> + User.schema.autoupdate (err) -> + test.done() + it 'should disconnect when done', (test) -> schema.disconnect() test.done()