Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HCK-8842: Fix RE for cross schema views #97

Merged
merged 5 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions adapter/0.2.12.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 @@ -138,7 +138,7 @@ module.exports = {
]);
callback(
null,
mergeCollectionsWithViews(jsonSchemas),
mergeCollectionsWithViews({ jsonSchemas, _ }),
chulanovskyi-bs marked this conversation as resolved.
Show resolved Hide resolved
modelInfo,
filterRelationships(relationships, jsonSchemas),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,38 +37,20 @@ const {
} = require('./helpers');
const pipe = require('../helpers/pipe');

const mergeCollectionsWithViews = jsonSchemas => {
return jsonSchemas.reduce((structuredJSONSchemas, jsonSchema) => {
if (jsonSchema.relatedTables) {
const currentIndex = structuredJSONSchemas.findIndex(
structuredSchema =>
jsonSchema.collectionName === structuredSchema.collectionName &&
jsonSchema.dbName === structuredSchema.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);
} else {
structuredJSONSchemas.push({
dbName: jsonSchema.dbName,
entityLevel: {},
views: [jsonSchema],
emptyBucket: false,
bucketInfo: jsonSchema.bucketInfo,
});
}

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 => {
Expand Down