Skip to content

Commit ea33f55

Browse files
darknosSakib Hasan
authored and
Sakib Hasan
committed
Properties with mysql custom "columnName" don't get autoupdated (#273)
* #250 fix column escaping for autoupdate * Fix lint error
1 parent 345492e commit ea33f55

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

lib/migration.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ function mixinMigration(MySQL, mysql) {
176176
});
177177
}
178178
if (found) {
179-
actualize(colName, found);
179+
actualize(propName, found);
180180
} else {
181181
sql.push('ADD COLUMN ' + self.client.escapeId(colName) + ' ' +
182182
self.buildColumnDefinition(model, propName));
@@ -186,7 +186,7 @@ function mixinMigration(MySQL, mysql) {
186186
function actualize(propName, oldSettings) {
187187
var newSettings = m.properties[propName];
188188
if (newSettings && changed(newSettings, oldSettings)) {
189-
var pName = self.client.escapeId(propName);
189+
var pName = self.columnEscaped(model, propName);
190190
sql.push('CHANGE COLUMN ' + pName + ' ' + pName + ' ' +
191191
self.buildColumnDefinition(model, propName));
192192
}

test/mysql.autoupdate.test.js

+43
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,49 @@ describe('MySQL connector', function() {
529529
verifyMysqlColumnNameAutoupdate(done);
530530
});
531531

532+
it('should update the nullable property of "first_name" to false', function(done) {
533+
// update the model "required" property
534+
var schema = {
535+
name: 'ColRenameTest',
536+
options: {
537+
idInjection: false,
538+
mysql: {
539+
schema: 'myapp_test',
540+
table: 'col_rename_test',
541+
},
542+
},
543+
properties: {
544+
firstName: {
545+
type: 'String',
546+
required: true,
547+
length: 40,
548+
mysql: {
549+
columnName: 'first_name',
550+
dataType: 'varchar',
551+
dataLength: 40,
552+
},
553+
},
554+
lastName: {
555+
type: 'String',
556+
required: false,
557+
length: 40,
558+
},
559+
},
560+
};
561+
562+
ds.createModel(schema.name, schema.properties, schema.options);
563+
564+
// nullable should be updated to false
565+
ds.autoupdate('ColRenameTest', function(err) {
566+
assert.ifError(err);
567+
ds.discoverModelProperties('col_rename_test', function(err, props) {
568+
assert.equal(props[0].nullable, 'N');
569+
assert.equal(props[0].columnName, 'first_name');
570+
done();
571+
});
572+
});
573+
});
574+
532575
function verifyMysqlColumnNameAutoupdate(done) {
533576
ds.autoupdate('ColRenameTest', function(err) {
534577
ds.discoverModelProperties('col_rename_test', function(err, props) {

0 commit comments

Comments
 (0)