fix: add missing property in model generated

Signed-off-by: Muhammad Aaqil <aaqilniz@yahoo.com>

Update lib/datasource.js

Co-authored-by: Samarpan Bhattacharya <this.is.samy@gmail.com>
This commit is contained in:
Muhammad Aaqil 2022-10-16 13:20:52 +05:00 committed by Diana Lau
parent d29bec72a8
commit 6ffad9f7d6
2 changed files with 21 additions and 3 deletions

View File

@ -1666,11 +1666,12 @@ DataSource.prototype.discoverSchemas = function(tableName, options, cb) {
const propName = nameMapper('column', item.columnName); const propName = nameMapper('column', item.columnName);
schema.properties[propName] = { schema.properties[propName] = {
type: item.type, 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), item.nullable === 0 || item.nullable === false),
length: item.dataLength, length: item.dataLength,
precision: item.dataPrecision, precision: item.dataPrecision,
scale: item.dataScale, scale: item.dataScale,
generated: item.generated,
}; };
if (pks[item.columnName]) { if (pks[item.columnName]) {
@ -1683,6 +1684,7 @@ DataSource.prototype.discoverSchemas = function(tableName, options, cb) {
dataPrecision: item.dataPrecision, dataPrecision: item.dataPrecision,
dataScale: item.dataScale, dataScale: item.dataScale,
nullable: item.nullable, nullable: item.nullable,
generated: item.generated,
}; };
// merge connector-specific properties // merge connector-specific properties
if (item[dbType]) { if (item[dbType]) {
@ -1830,10 +1832,11 @@ DataSource.prototype.discoverSchemasSync = function(modelName, options) {
const propName = nameMapper('column', item.columnName); const propName = nameMapper('column', item.columnName);
schema.properties[propName] = { schema.properties[propName] = {
type: item.type, type: item.type,
required: (item.nullable === 'N'), required: !item.generated && item.nullable === 'N',
length: item.dataLength, length: item.dataLength,
precision: item.dataPrecision, precision: item.dataPrecision,
scale: item.dataScale, scale: item.dataScale,
generated: item.generated,
}; };
if (pks[item.columnName]) { if (pks[item.columnName]) {
@ -1846,6 +1849,7 @@ DataSource.prototype.discoverSchemasSync = function(modelName, options) {
dataPrecision: item.dataPrecision, dataPrecision: item.dataPrecision,
dataScale: item.dataScale, dataScale: item.dataScale,
nullable: i.nullable, nullable: i.nullable,
generated: i.generated,
}; };
}); });

View File

@ -34,6 +34,7 @@ describe('Memory connector with mocked discovery', function() {
dataPrecision: null, dataPrecision: null,
dataScale: null, dataScale: null,
nullable: 0, nullable: 0,
generated: true,
}, },
{ {
owner: 'STRONGLOOP', owner: 'STRONGLOOP',
@ -44,6 +45,7 @@ describe('Memory connector with mocked discovery', function() {
dataPrecision: null, dataPrecision: null,
dataScale: null, dataScale: null,
nullable: 0, nullable: 0,
generated: undefined,
}, },
{ {
owner: 'STRONGLOOP', owner: 'STRONGLOOP',
@ -54,6 +56,7 @@ describe('Memory connector with mocked discovery', function() {
dataPrecision: 10, dataPrecision: 10,
dataScale: 0, dataScale: 0,
nullable: 1, nullable: 1,
generated: undefined,
}, },
{ {
owner: 'STRONGLOOP', owner: 'STRONGLOOP',
@ -64,6 +67,7 @@ describe('Memory connector with mocked discovery', function() {
dataPrecision: 10, dataPrecision: 10,
dataScale: 0, dataScale: 0,
nullable: 1, nullable: 1,
generated: undefined,
}]; }];
ds.discoverModelProperties = function(modelName, options, cb) { ds.discoverModelProperties = function(modelName, options, cb) {
@ -214,11 +218,13 @@ describe('Memory connector with mocked discovery', function() {
dataScale: 0, dataScale: 0,
dataType: 'int', dataType: 'int',
nullable: 1, nullable: 1,
generated: undefined,
}, },
precision: 10, precision: 10,
required: false, required: false,
scale: 0, scale: 0,
type: undefined, type: undefined,
generated: undefined,
}, },
locationId: { locationId: {
length: 20, length: 20,
@ -229,11 +235,13 @@ describe('Memory connector with mocked discovery', function() {
dataScale: null, dataScale: null,
dataType: 'varchar', dataType: 'varchar',
nullable: 0, nullable: 0,
generated: undefined,
}, },
precision: null, precision: null,
required: true, required: true,
scale: null, scale: null,
type: undefined, type: undefined,
generated: undefined,
}, },
productId: { productId: {
length: 20, length: 20,
@ -244,11 +252,13 @@ describe('Memory connector with mocked discovery', function() {
dataScale: null, dataScale: null,
dataType: 'varchar', dataType: 'varchar',
nullable: 0, nullable: 0,
generated: true,
}, },
precision: null, precision: null,
required: true, required: false,
scale: null, scale: null,
type: undefined, type: undefined,
generated: true,
}, },
total: { total: {
length: null, length: null,
@ -259,11 +269,13 @@ describe('Memory connector with mocked discovery', function() {
dataScale: 0, dataScale: 0,
dataType: 'int', dataType: 'int',
nullable: 1, nullable: 1,
generated: undefined,
}, },
precision: 10, precision: 10,
required: false, required: false,
scale: 0, scale: 0,
type: undefined, type: undefined,
generated: undefined,
}, },
}, },
}; };
@ -381,6 +393,7 @@ describe('discoverModelProperties', function() {
dataPrecision: null, dataPrecision: null,
dataScale: null, dataScale: null,
nullable: 0, nullable: 0,
generated: undefined,
}, },
{ {
owner: 'STRONGLOOP', owner: 'STRONGLOOP',
@ -391,6 +404,7 @@ describe('discoverModelProperties', function() {
dataPrecision: null, dataPrecision: null,
dataScale: null, dataScale: null,
nullable: 0, nullable: 0,
generated: undefined,
}, },
{ {
owner: 'STRONGLOOP', owner: 'STRONGLOOP',