Skip to content

Commit 708bbc5

Browse files
HCK-8843: Fix RE for cross schema views (#119)
* HCK-8843: remove relative table binding for view * HCK-8843: add an adapter to clear viewOn property
1 parent 5260053 commit 708bbc5

File tree

3 files changed

+69
-22
lines changed

3 files changed

+69
-22
lines changed

adapter/0.2.13.json

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/**
2+
* Copyright © 2016-2024 by IntegrIT S.A. dba Hackolade. All rights reserved.
3+
*
4+
* The copyright to the computer software herein is the property of IntegrIT S.A.
5+
* The software may be used and/or copied only with the written permission of
6+
* IntegrIT S.A. or in accordance with the terms and conditions stipulated in
7+
* the agreement/contract under which the software has been supplied.
8+
*
9+
* {
10+
* "add": {
11+
* "entity": [<names of new property>],
12+
* "container": [<names of new property>],
13+
* "model": [<names of new property>],
14+
* "view": [<names of new property>],
15+
* "field": {
16+
* "<type>": [<names of new property>]
17+
* }
18+
* },
19+
* "delete": {
20+
* "entity": [<names of new property>],
21+
* "container": [<names of new property>],
22+
* "model": [<names of new property>],
23+
* "view": [<names of new property>],
24+
* "field": {
25+
* "<type>": [<names of new property>]
26+
* }
27+
* },
28+
* "modify": {
29+
* "entity": [
30+
* {
31+
* "from": { <properties that identify record> },
32+
* "to": { <properties that need to be changed> }
33+
* }
34+
* ],
35+
* "container": [],
36+
* "model": [],
37+
* "view": [],
38+
* "field": []
39+
* },
40+
* }
41+
*/
42+
{
43+
"modify": {
44+
"view": [
45+
{
46+
"from": {},
47+
"to": {
48+
"viewOn": ""
49+
}
50+
}
51+
]
52+
}
53+
}

reverse_engineering/api.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ module.exports = {
140140
});
141141
callback(
142142
null,
143-
mergeCollectionsWithViews(jsonSchemasWithDescriptionComments),
143+
mergeCollectionsWithViews({ jsonSchemas: jsonSchemasWithDescriptionComments }),
144144
null,
145145
filterRelationships(relationships, jsonSchemasWithDescriptionComments),
146146
);

reverse_engineering/reverseEngineeringService/reverseEngineeringService.js

+15-21
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
const { groupBy, omit, partition } = require('lodash');
12
const {
23
getTableInfo,
34
getTableRow,
@@ -42,28 +43,21 @@ const {
4243
} = require('./helpers');
4344
const pipe = require('../helpers/pipe');
4445

45-
const mergeCollectionsWithViews = jsonSchemas =>
46-
jsonSchemas.reduce((structuredJSONSchemas, jsonSchema) => {
47-
if (jsonSchema.relatedTables) {
48-
const currentIndex = structuredJSONSchemas.findIndex(
49-
structuredSchema => jsonSchema.collectionName === structuredSchema.collectionName && jsonSchema.dbName,
50-
);
51-
const relatedTableSchemaIndex = structuredJSONSchemas.findIndex(({ collectionName, dbName }) =>
52-
jsonSchema.relatedTables.find(
53-
({ tableName, schemaName }) => tableName === collectionName && schemaName === dbName,
54-
),
55-
);
56-
57-
if (relatedTableSchemaIndex !== -1 && doesViewHaveRelatedTables(jsonSchema, structuredJSONSchemas)) {
58-
structuredJSONSchemas[relatedTableSchemaIndex].views.push(jsonSchema);
59-
}
60-
61-
delete jsonSchema.relatedTables;
62-
return structuredJSONSchemas.filter((schema, i) => i !== currentIndex);
63-
}
46+
const mergeCollectionsWithViews = ({ jsonSchemas }) => {
47+
const [viewSchemas, collectionSchemas] = partition(jsonSchemas, jsonSchema => jsonSchema.relatedTables);
48+
const groupedViewSchemas = groupBy(viewSchemas, 'dbName');
49+
const combinedViewSchemas = Object.entries(groupedViewSchemas).map(([dbName, views]) => {
50+
return {
51+
dbName,
52+
entityLevel: {},
53+
emptyBucket: false,
54+
bucketInfo: views[0].bucketInfo,
55+
views: views.map(view => omit(view, ['relatedTables'])),
56+
};
57+
});
6458

65-
return structuredJSONSchemas;
66-
}, jsonSchemas);
59+
return [...collectionSchemas, ...combinedViewSchemas];
60+
};
6761

6862
const getCollectionsRelationships = logger => async dbConnectionClient => {
6963
const dbName = dbConnectionClient.config.database;

0 commit comments

Comments
 (0)