Skip to content

Commit

Permalink
HCK-8843: Fix RE for cross schema views (#119)
Browse files Browse the repository at this point in the history
* HCK-8843: remove relative table binding for view

* HCK-8843: add an adapter to clear viewOn property
  • Loading branch information
serhii-filonenko authored Nov 22, 2024
1 parent 5260053 commit 708bbc5
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 22 deletions.
53 changes: 53 additions & 0 deletions adapter/0.2.13.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* Copyright © 2016-2024 by IntegrIT S.A. dba Hackolade. All rights reserved.
*
* The copyright to the computer software herein is the property of IntegrIT S.A.
* The software may be used and/or copied only with the written permission of
* IntegrIT S.A. or in accordance with the terms and conditions stipulated in
* the agreement/contract under which the software has been supplied.
*
* {
* "add": {
* "entity": [<names of new property>],
* "container": [<names of new property>],
* "model": [<names of new property>],
* "view": [<names of new property>],
* "field": {
* "<type>": [<names of new property>]
* }
* },
* "delete": {
* "entity": [<names of new property>],
* "container": [<names of new property>],
* "model": [<names of new property>],
* "view": [<names of new property>],
* "field": {
* "<type>": [<names of new property>]
* }
* },
* "modify": {
* "entity": [
* {
* "from": { <properties that identify record> },
* "to": { <properties that need to be changed> }
* }
* ],
* "container": [],
* "model": [],
* "view": [],
* "field": []
* },
* }
*/
{
"modify": {
"view": [
{
"from": {},
"to": {
"viewOn": ""
}
}
]
}
}
2 changes: 1 addition & 1 deletion reverse_engineering/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ module.exports = {
});
callback(
null,
mergeCollectionsWithViews(jsonSchemasWithDescriptionComments),
mergeCollectionsWithViews({ jsonSchemas: jsonSchemasWithDescriptionComments }),
null,
filterRelationships(relationships, jsonSchemasWithDescriptionComments),
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const { groupBy, omit, partition } = require('lodash');
const {
getTableInfo,
getTableRow,
Expand Down Expand Up @@ -42,28 +43,21 @@ const {
} = require('./helpers');
const pipe = require('../helpers/pipe');

const mergeCollectionsWithViews = jsonSchemas =>
jsonSchemas.reduce((structuredJSONSchemas, jsonSchema) => {
if (jsonSchema.relatedTables) {
const currentIndex = structuredJSONSchemas.findIndex(
structuredSchema => jsonSchema.collectionName === structuredSchema.collectionName && jsonSchema.dbName,
);
const relatedTableSchemaIndex = structuredJSONSchemas.findIndex(({ collectionName, dbName }) =>
jsonSchema.relatedTables.find(
({ tableName, schemaName }) => tableName === collectionName && schemaName === dbName,
),
);

if (relatedTableSchemaIndex !== -1 && doesViewHaveRelatedTables(jsonSchema, structuredJSONSchemas)) {
structuredJSONSchemas[relatedTableSchemaIndex].views.push(jsonSchema);
}

delete jsonSchema.relatedTables;
return structuredJSONSchemas.filter((schema, i) => i !== currentIndex);
}
const mergeCollectionsWithViews = ({ jsonSchemas }) => {
const [viewSchemas, collectionSchemas] = partition(jsonSchemas, jsonSchema => jsonSchema.relatedTables);
const groupedViewSchemas = groupBy(viewSchemas, 'dbName');
const combinedViewSchemas = Object.entries(groupedViewSchemas).map(([dbName, views]) => {
return {
dbName,
entityLevel: {},
emptyBucket: false,
bucketInfo: views[0].bucketInfo,
views: views.map(view => omit(view, ['relatedTables'])),
};
});

return structuredJSONSchemas;
}, jsonSchemas);
return [...collectionSchemas, ...combinedViewSchemas];
};

const getCollectionsRelationships = logger => async dbConnectionClient => {
const dbName = dbConnectionClient.config.database;
Expand Down

0 comments on commit 708bbc5

Please sign in to comment.