Properties with mysql custom "columnName" don't get autoupdated (#273)

* #250 fix column escaping for autoupdate

* Fix lint error
This commit is contained in:
Sergey Nosenko 2017-04-28 00:31:20 +03:00 committed by Sakib Hasan
parent 345492e5b2
commit ea33f557ab
2 changed files with 45 additions and 2 deletions

View File

@ -176,7 +176,7 @@ function mixinMigration(MySQL, mysql) {
});
}
if (found) {
actualize(colName, found);
actualize(propName, found);
} else {
sql.push('ADD COLUMN ' + self.client.escapeId(colName) + ' ' +
self.buildColumnDefinition(model, propName));
@ -186,7 +186,7 @@ function mixinMigration(MySQL, mysql) {
function actualize(propName, oldSettings) {
var newSettings = m.properties[propName];
if (newSettings && changed(newSettings, oldSettings)) {
var pName = self.client.escapeId(propName);
var pName = self.columnEscaped(model, propName);
sql.push('CHANGE COLUMN ' + pName + ' ' + pName + ' ' +
self.buildColumnDefinition(model, propName));
}

View File

@ -529,6 +529,49 @@ describe('MySQL connector', function() {
verifyMysqlColumnNameAutoupdate(done);
});
it('should update the nullable property of "first_name" to false', function(done) {
// update the model "required" property
var schema = {
name: 'ColRenameTest',
options: {
idInjection: false,
mysql: {
schema: 'myapp_test',
table: 'col_rename_test',
},
},
properties: {
firstName: {
type: 'String',
required: true,
length: 40,
mysql: {
columnName: 'first_name',
dataType: 'varchar',
dataLength: 40,
},
},
lastName: {
type: 'String',
required: false,
length: 40,
},
},
};
ds.createModel(schema.name, schema.properties, schema.options);
// nullable should be updated to false
ds.autoupdate('ColRenameTest', function(err) {
assert.ifError(err);
ds.discoverModelProperties('col_rename_test', function(err, props) {
assert.equal(props[0].nullable, 'N');
assert.equal(props[0].columnName, 'first_name');
done();
});
});
});
function verifyMysqlColumnNameAutoupdate(done) {
ds.autoupdate('ColRenameTest', function(err) {
ds.discoverModelProperties('col_rename_test', function(err, props) {