From ea33f557ab579ebd64c2a1db758781ea55576d39 Mon Sep 17 00:00:00 2001 From: Sergey Nosenko Date: Fri, 28 Apr 2017 00:31:20 +0300 Subject: [PATCH] Properties with mysql custom "columnName" don't get autoupdated (#273) * #250 fix column escaping for autoupdate * Fix lint error --- lib/migration.js | 4 ++-- test/mysql.autoupdate.test.js | 43 +++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/lib/migration.js b/lib/migration.js index 1d097ed..c5ee63b 100644 --- a/lib/migration.js +++ b/lib/migration.js @@ -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)); } diff --git a/test/mysql.autoupdate.test.js b/test/mysql.autoupdate.test.js index 98077d2..c543606 100644 --- a/test/mysql.autoupdate.test.js +++ b/test/mysql.autoupdate.test.js @@ -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) {