From c6edd820d1013d87f32973696e11a25b8696898d Mon Sep 17 00:00:00 2001 From: Sergey Nosenko Date: Thu, 27 Apr 2017 19:49:55 +0300 Subject: [PATCH 1/2] #250 fix column escaping for autoupdate --- 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 1d097ed3..c5ee63b5 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 98077d2a..c5484210 100644 --- a/test/mysql.autoupdate.test.js +++ b/test/mysql.autoupdate.test.js @@ -528,6 +528,49 @@ describe('MySQL connector', function() { // second autoupdate call uses alter table 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) { From aa4b56d8f8381d4bd7b23be7a8743dd96ed947cc Mon Sep 17 00:00:00 2001 From: ssh24 Date: Thu, 27 Apr 2017 16:49:40 -0400 Subject: [PATCH 2/2] Fix lint error --- test/mysql.autoupdate.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/mysql.autoupdate.test.js b/test/mysql.autoupdate.test.js index c5484210..c5436063 100644 --- a/test/mysql.autoupdate.test.js +++ b/test/mysql.autoupdate.test.js @@ -528,7 +528,7 @@ describe('MySQL connector', function() { // second autoupdate call uses alter table verifyMysqlColumnNameAutoupdate(done); }); - + it('should update the nullable property of "first_name" to false', function(done) { // update the model "required" property var schema = {