From 447e0ca2beed5124831d93d79b249e476dcfc53c Mon Sep 17 00:00:00 2001 From: Muhammad Aaqil Date: Tue, 17 Oct 2023 13:36:14 +0500 Subject: [PATCH] fix: return enum type Signed-off-by: Muhammad Aaqil --- lib/discovery.js | 3 ++- test/mysql.discover.test.js | 16 ++++++++++++++++ test/schema.sql | 17 +++++++++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/lib/discovery.js b/lib/discovery.js index 5963f3f1..a9cf6c2c 100644 --- a/lib/discovery.js +++ b/lib/discovery.js @@ -340,7 +340,6 @@ function mixinDiscovery(MySQL, mysql) { case 'MEDIUMTEXT': case 'LONGTEXT': case 'TEXT': - case 'ENUM': case 'SET': return 'String'; case 'TINYBLOB': @@ -380,6 +379,8 @@ function mixinDiscovery(MySQL, mysql) { case 'BOOL': case 'BOOLEAN': return 'Boolean'; + case 'ENUM': + return columnType; default: return 'String'; } diff --git a/test/mysql.discover.test.js b/test/mysql.discover.test.js index d2b97c3e..4fd1f290 100644 --- a/test/mysql.discover.test.js +++ b/test/mysql.discover.test.js @@ -257,6 +257,22 @@ describe('Discover LDL schema from a table', function() { }); }); +describe('Discover and handle enum', function() { + let schema; + before(function(done) { + db.discoverSchema('PATIENT', {owner: 'STRONGLOOP'}, function(err, schema_) { + schema = schema_; + done(err); + }); + }); + it('should validate enum type for PATIENT', function() { + assert.ok(/STRONGLOOP/i.test(schema.options.mysql.schema)); + assert.strictEqual(schema.options.mysql.table, 'PATIENT'); + assert.strictEqual(schema.name, 'Patient'); + assert.strictEqual(schema.properties.type.type, "enum('INPATIENT','OUTPATIENT')"); + }); +}); + describe('Discover and build models', function() { let models; before(function(done) { diff --git a/test/schema.sql b/test/schema.sql index c0bf5082..589b3d1b 100644 --- a/test/schema.sql +++ b/test/schema.sql @@ -49,6 +49,23 @@ LOCK TABLES `CUSTOMER` WRITE; /*!40000 ALTER TABLE `CUSTOMER` ENABLE KEYS */; UNLOCK TABLES; + +-- +-- Table structure for table `INVENTORY` +-- + +DROP TABLE IF EXISTS `PATIENT`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `PATIENT` ( + `ID` varchar(20) NOT NULL, + `NAME` varchar(20) NOT NULL, + `TYPE` ENUM('INPATIENT', 'OUTPATIENT') DEFAULT NULL, + PRIMARY KEY (`ID`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8; +/*!40101 SET character_set_client = @saved_cs_client */; + + -- -- Table structure for table `INVENTORY` --