Skip to content

Commit 45c5e7c

Browse files
committed
fix: mark a property generated if it is STORED or VIRTUAL
Signed-off-by: Muhammad Aaqil <[email protected]>
1 parent b057c20 commit 45c5e7c

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

lib/discovery.js

+16-2
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,14 @@ function mixinDiscovery(MySQL, mysql) {
166166
' numeric_scale AS "dataScale",' +
167167
' column_type AS "columnType",' +
168168
' is_nullable = \'YES\' AS "nullable",' +
169-
' CASE WHEN extra LIKE \'%auto_increment%\' THEN 1 ELSE 0 END AS "generated"' +
169+
`
170+
case
171+
when extra like '%virtual%' then 1
172+
when extra like '%stored%' then 1
173+
when extra LIKE '%auto_increment%' THEN 1
174+
else 0
175+
end as "generated"
176+
` +
170177
' FROM information_schema.columns' +
171178
' WHERE table_schema=' + mysql.escape(schema) +
172179
(table ? ' AND table_name=' + mysql.escape(table) : ''),
@@ -181,7 +188,14 @@ function mixinDiscovery(MySQL, mysql) {
181188
' numeric_scale AS "dataScale",' +
182189
' column_type AS "columnType",' +
183190
' is_nullable = \'YES\' AS "nullable",' +
184-
' CASE WHEN extra LIKE \'%auto_increment%\' THEN 1 ELSE 0 END AS "generated"' +
191+
`
192+
case
193+
when extra like '%virtual%' then 1
194+
when extra like '%stored%' then 1
195+
when extra LIKE '%auto_increment%' THEN 1
196+
else 0
197+
end as "generated"
198+
` +
185199
' FROM information_schema.columns' +
186200
(table ? ' WHERE table_name=' + mysql.escape(table) : ''),
187201
'table_name, ordinal_position', {});

test/mysql.discover.test.js

+12
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,18 @@ describe('Discover model generated columns', function() {
251251
done();
252252
});
253253
});
254+
it('should mark STORED column as generated', function(done) {
255+
db.discoverModelProperties('testgen', function(err, models) {
256+
if (err) return done(err);
257+
models.forEach(function(model) {
258+
assert(model.tableName.toLowerCase() === 'testgen');
259+
if (model.columnName === 'TOKEN') {
260+
assert(model.generated, 'STRONGLOOP.TESTGEN.TOKEN should be a generated (identity) column');
261+
}
262+
});
263+
done();
264+
});
265+
});
254266
});
255267

256268
describe('Discover LDL schema from a table', function() {

test/schema.sql

+2-1
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,9 @@ DROP TABLE IF EXISTS `TESTGEN`;
217217
CREATE TABLE `TESTGEN` (
218218
`ID` int(11) NOT NULL AUTO_INCREMENT,
219219
`NAME` varchar(64) DEFAULT NULL,
220+
`TOKEN` CHAR(32) GENERATED ALWAYS AS (MD5(NAME)) STORED,
220221
PRIMARY KEY (`ID`)
221-
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
222+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
222223
/*!40101 SET character_set_client = @saved_cs_client */;
223224

224225
--

0 commit comments

Comments
 (0)