diff --git a/test/mysql.discover.test.js b/test/mysql.discover.test.js index 5c176fd..c11ebd0 100644 --- a/test/mysql.discover.test.js +++ b/test/mysql.discover.test.js @@ -206,6 +206,42 @@ describe('Discover model foreign keys', function() { }); }); +describe('Discover model generated columns', function() { + it('should return an array of columns for STRONGLOOP.PRODUCT and none of them is generated', function(done) { + db.discoverModelProperties('product', function(err, models) { + if (err) { + console.error(err); + done(err); + } else { + models.forEach(function(m) { + // console.dir(m); + assert(m.tableName === 'PRODUCT'); + assert(!m.generated, 'STRONGLOOP.PRODUCT table should not have generated (identity) columns'); + + }); + done(null, models); + } + }); + }); + it('should return an array of columns for STRONGLOOP.TESTGEN and the first is generated', function(done) { + db.discoverModelProperties('testgen', function(err, models) { + if (err) { + console.error(err); + done(err); + } else { + models.forEach(function(m) { + // console.dir(m); + assert(m.tableName === 'TESTGEN'); + if (m.columnName === 'ID') { + assert(m.generated, 'STRONGLOOP.TESTGEN.ID should be a generated (identity) column'); + } + }); + done(null, models); + } + }); + }); +}); + describe('Discover LDL schema from a table', function() { var schema; before(function(done) { diff --git a/test/schema.sql b/test/schema.sql index 3f10afb..d7741d9 100644 --- a/test/schema.sql +++ b/test/schema.sql @@ -86,7 +86,7 @@ DROP TABLE IF EXISTS `INVENTORY_VIEW`; /*!50001 DROP VIEW IF EXISTS `INVENTORY_VIEW`*/; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; -/*!50001 CREATE VIEW `INVENTORY_VIEW` AS SELECT +/*!50001 CREATE VIEW `INVENTORY_VIEW` AS SELECT 1 AS `ID`, 1 AS `PRODUCT_ID`, 1 AS `PRODUCT_NAME`, @@ -189,6 +189,19 @@ LOCK TABLES `RESERVATION` WRITE; /*!40000 ALTER TABLE `RESERVATION` ENABLE KEYS */; UNLOCK TABLES; +-- +-- Table structure for table `TESTGEN` +-- + +DROP TABLE IF EXISTS `TESTGEN`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `TESTGEN` ( + `ID` int(11) NOT NULL AUTO_INCREMENT, + `NAME` varchar(64) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=utf8; +/*!40101 SET character_set_client = @saved_cs_client */; + -- -- Current Database: `STRONGLOOP` --