Escape index names (#280)

* Escape index names

* Add test cases
This commit is contained in:
Sakib Hasan 2017-05-19 11:57:06 -04:00 committed by GitHub
parent 18ddc84929
commit 2ba88203f3
2 changed files with 52 additions and 2 deletions

View File

@ -662,11 +662,11 @@ function mixinMigration(MySQL, mysql) {
//for each field in "keys" object
for (var key in i.keys) {
if (i.keys[key] !== -1) {
indexedColumns.push(key);
indexedColumns.push(this.escapeName(key));
} else {
//mysql does not support index sorting Currently
//but mysql has added DESC keyword for future support
indexedColumns.push(key + ' DESC ');
indexedColumns.push(this.escapeName(key) + ' DESC ');
}
}
}

View File

@ -17,6 +17,56 @@ describe('MySQL connector', function() {
setupAltColNameData();
});
describe('escape index names upon automigrate', function() {
before (function(done) {
var messageSchema = {
'name': 'Message',
'options': {
'idInjection': false,
'indexes': {
'id_index': {
'keys': {
'id': 1,
},
},
'from_index': {
'keys': {
'from': 1,
},
},
},
},
'properties': {
'id': {
'type': 'number',
'id': true,
'generated': false,
},
'conversation': {
'type': 'string',
},
'from': {
'type': 'number',
},
'sent': {
'type': 'date',
},
},
};
ds.createModel(messageSchema.name, messageSchema.properties, messageSchema.options);
done();
});
it('should escape index names', function(done) {
// please note `from` is a keyword in mysql https://dev.mysql.com/doc/refman/5.7/en/keywords.html
// hence it needs to be escaped in order for it to work
// instead of escaping the special keywords, we escape all index names
ds.automigrate('Message', function(err) {
assert(!err);
done();
});
});
});
it('should auto migrate/update tables', function(done) {
var schema_v1 = {
'name': 'CustomerTest',