From 91f6d25ffc175dfaf538029ec6c3a4a68d7b5a85 Mon Sep 17 00:00:00 2001 From: Muhammad Aaqil Date: Sat, 16 Mar 2024 13:13:58 +0500 Subject: [PATCH] fix: change condition to treat tinyint as boolean Signed-off-by: Muhammad Aaqil --- lib/discovery.js | 4 ++-- test/mysql.discover.test.js | 6 +++++- test/schema.sql | 1 + 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/discovery.js b/lib/discovery.js index a9cf6c2c..3c8a228d 100644 --- a/lib/discovery.js +++ b/lib/discovery.js @@ -355,8 +355,8 @@ function mixinDiscovery(MySQL, mysql) { } return 'Binary'; case 'TINYINT': - // treat TINYINT(1) as boolean as it is aliased as BOOL and BOOLEAN in mysql - if (!options.treatTINYINT1AsTinyInt && columnType === 'tinyint(1)') { + // treat TINYINT as boolean as it is aliased as BOOL and BOOLEAN in mysql + if (!options.treatTINYINT1AsTinyInt && columnType.includes('tinyint')) { return 'Boolean'; } case 'SMALLINT': diff --git a/test/mysql.discover.test.js b/test/mysql.discover.test.js index 4fd1f290..1296a66c 100644 --- a/test/mysql.discover.test.js +++ b/test/mysql.discover.test.js @@ -476,7 +476,6 @@ describe('Discover and build models', function() { context('with flag treatTINYINT1AsTinyInt = false', function() { let models, schema; before(discoverAndBuildModels); - it('handles CHAR(1) as Boolean', function() { assert(schema.properties.enabled); assert.strictEqual(schema.properties.enabled.type, Boolean); @@ -526,6 +525,11 @@ describe('Discover and build models', function() { assert.strictEqual(schema.properties.active.type, Boolean); }); + it('handles TINYINT as Boolean', function() { + assert(schema.properties.archived); + assert.strictEqual(schema.properties.archived.type, Boolean); + }); + function discoverAndBuildModels(done) { db.discoverAndBuildModels('INVENTORY', { owner: 'STRONGLOOP', diff --git a/test/schema.sql b/test/schema.sql index 589b3d1b..43e45ff4 100644 --- a/test/schema.sql +++ b/test/schema.sql @@ -79,6 +79,7 @@ CREATE TABLE `INVENTORY` ( `AVAILABLE` int(11) DEFAULT NULL, `TOTAL` int(11) DEFAULT NULL, `ACTIVE` BOOLEAN DEFAULT TRUE, + `ARCHIVED` TINYINT DEFAULT 1, `DISABLED` BIT(1) DEFAULT 0, `ENABLED` CHAR(1) DEFAULT 'Y', PRIMARY KEY (`PRODUCT_ID`,`LOCATION_ID`),