fix: discover properties with json type

Signed-off-by: Muhammad Aaqil <aaqilcs102@gmail.com>
This commit is contained in:
Muhammad Aaqil 2024-05-21 15:51:45 +05:00 committed by Diana Lau
parent 3ae4b5ecf0
commit 77b2c401f8
3 changed files with 19 additions and 0 deletions

View File

@ -382,6 +382,8 @@ function mixinDiscovery(MySQL, mysql) {
case 'BOOL': case 'BOOL':
case 'BOOLEAN': case 'BOOLEAN':
return 'Boolean'; return 'Boolean';
case 'JSON':
return 'object';
case 'ENUM': case 'ENUM':
return columnType; return columnType;
default: default:

View File

@ -299,6 +299,22 @@ describe('Discover and handle enum', function() {
}); });
}); });
describe('Discover models with JSON type columns', function() {
let schema;
before(function(done) {
db.discoverSchema('INVENTORY', {owner: 'STRONGLOOP'}, function(err, schema_) {
schema = schema_;
done(err);
});
});
it('should validate JSON as an object type for INVENTORY', function() {
assert.ok(/STRONGLOOP/i.test(schema.options.mysql.schema));
assert.strictEqual(schema.options.mysql.table, 'INVENTORY');
assert.strictEqual(schema.name, 'Inventory');
assert.strictEqual(schema.properties.details.type, 'object');
});
});
describe('Discover and build models', function() { describe('Discover and build models', function() {
let models; let models;
before(function(done) { before(function(done) {

View File

@ -78,6 +78,7 @@ CREATE TABLE `INVENTORY` (
`LOCATION_ID` varchar(20) NOT NULL, `LOCATION_ID` varchar(20) NOT NULL,
`AVAILABLE` int(11) DEFAULT NULL, `AVAILABLE` int(11) DEFAULT NULL,
`TOTAL` int(11) DEFAULT NULL, `TOTAL` int(11) DEFAULT NULL,
`DETAILS` json DEFAULT NULL,
`ACTIVE` BOOLEAN DEFAULT TRUE, `ACTIVE` BOOLEAN DEFAULT TRUE,
`DISABLED` BIT(1) DEFAULT 0, `DISABLED` BIT(1) DEFAULT 0,
`ENABLED` CHAR(1) DEFAULT 'Y', `ENABLED` CHAR(1) DEFAULT 'Y',