From 6ffad9f7d6182bd65ae2b18bbcb60b8a162c50ff Mon Sep 17 00:00:00 2001 From: Muhammad Aaqil Date: Sun, 16 Oct 2022 13:20:52 +0500 Subject: [PATCH] fix: add missing property in model generated Signed-off-by: Muhammad Aaqil Update lib/datasource.js Co-authored-by: Samarpan Bhattacharya --- lib/datasource.js | 8 ++++++-- test/discovery.test.js | 16 +++++++++++++++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/lib/datasource.js b/lib/datasource.js index 13c6a714..0ca42831 100644 --- a/lib/datasource.js +++ b/lib/datasource.js @@ -1666,11 +1666,12 @@ DataSource.prototype.discoverSchemas = function(tableName, options, cb) { const propName = nameMapper('column', item.columnName); schema.properties[propName] = { type: item.type, - required: (item.nullable === 'N' || item.nullable === 'NO' || + required: !item.generated && (item.nullable === 'N' || item.nullable === 'NO' || item.nullable === 0 || item.nullable === false), length: item.dataLength, precision: item.dataPrecision, scale: item.dataScale, + generated: item.generated, }; if (pks[item.columnName]) { @@ -1683,6 +1684,7 @@ DataSource.prototype.discoverSchemas = function(tableName, options, cb) { dataPrecision: item.dataPrecision, dataScale: item.dataScale, nullable: item.nullable, + generated: item.generated, }; // merge connector-specific properties if (item[dbType]) { @@ -1830,10 +1832,11 @@ DataSource.prototype.discoverSchemasSync = function(modelName, options) { const propName = nameMapper('column', item.columnName); schema.properties[propName] = { type: item.type, - required: (item.nullable === 'N'), + required: !item.generated && item.nullable === 'N', length: item.dataLength, precision: item.dataPrecision, scale: item.dataScale, + generated: item.generated, }; if (pks[item.columnName]) { @@ -1846,6 +1849,7 @@ DataSource.prototype.discoverSchemasSync = function(modelName, options) { dataPrecision: item.dataPrecision, dataScale: item.dataScale, nullable: i.nullable, + generated: i.generated, }; }); diff --git a/test/discovery.test.js b/test/discovery.test.js index c84ee839..fadd7d5e 100644 --- a/test/discovery.test.js +++ b/test/discovery.test.js @@ -34,6 +34,7 @@ describe('Memory connector with mocked discovery', function() { dataPrecision: null, dataScale: null, nullable: 0, + generated: true, }, { owner: 'STRONGLOOP', @@ -44,6 +45,7 @@ describe('Memory connector with mocked discovery', function() { dataPrecision: null, dataScale: null, nullable: 0, + generated: undefined, }, { owner: 'STRONGLOOP', @@ -54,6 +56,7 @@ describe('Memory connector with mocked discovery', function() { dataPrecision: 10, dataScale: 0, nullable: 1, + generated: undefined, }, { owner: 'STRONGLOOP', @@ -64,6 +67,7 @@ describe('Memory connector with mocked discovery', function() { dataPrecision: 10, dataScale: 0, nullable: 1, + generated: undefined, }]; ds.discoverModelProperties = function(modelName, options, cb) { @@ -214,11 +218,13 @@ describe('Memory connector with mocked discovery', function() { dataScale: 0, dataType: 'int', nullable: 1, + generated: undefined, }, precision: 10, required: false, scale: 0, type: undefined, + generated: undefined, }, locationId: { length: 20, @@ -229,11 +235,13 @@ describe('Memory connector with mocked discovery', function() { dataScale: null, dataType: 'varchar', nullable: 0, + generated: undefined, }, precision: null, required: true, scale: null, type: undefined, + generated: undefined, }, productId: { length: 20, @@ -244,11 +252,13 @@ describe('Memory connector with mocked discovery', function() { dataScale: null, dataType: 'varchar', nullable: 0, + generated: true, }, precision: null, - required: true, + required: false, scale: null, type: undefined, + generated: true, }, total: { length: null, @@ -259,11 +269,13 @@ describe('Memory connector with mocked discovery', function() { dataScale: 0, dataType: 'int', nullable: 1, + generated: undefined, }, precision: 10, required: false, scale: 0, type: undefined, + generated: undefined, }, }, }; @@ -381,6 +393,7 @@ describe('discoverModelProperties', function() { dataPrecision: null, dataScale: null, nullable: 0, + generated: undefined, }, { owner: 'STRONGLOOP', @@ -391,6 +404,7 @@ describe('discoverModelProperties', function() { dataPrecision: null, dataScale: null, nullable: 0, + generated: undefined, }, { owner: 'STRONGLOOP',