From 225bfdb458efc75a5b8df342dba65fa1f26ce4ee Mon Sep 17 00:00:00 2001 From: Nazar Kovtun <88377450+WilhelmWesser@users.noreply.github.com> Date: Mon, 25 Nov 2024 16:25:05 +0200 Subject: [PATCH] HCK-8696: add filtering of duplicated indexes columns for case with indexes on partitioned tables (#121) * HCK-8696: add filtering of duplicated indexes columns for case with indexes on partitioned tables * HCK-8696: removed redundant Boolean call --- .../helpers/getUniqueIndexesColumns.js | 23 +++++++++++++++++++ .../reverseEngineeringService.js | 4 +++- 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 reverse_engineering/reverseEngineeringService/helpers/getUniqueIndexesColumns.js diff --git a/reverse_engineering/reverseEngineeringService/helpers/getUniqueIndexesColumns.js b/reverse_engineering/reverseEngineeringService/helpers/getUniqueIndexesColumns.js new file mode 100644 index 0000000..7350a24 --- /dev/null +++ b/reverse_engineering/reverseEngineeringService/helpers/getUniqueIndexesColumns.js @@ -0,0 +1,23 @@ +const getColumnUniqueKey = ({ IndexName, TableName, schemaName, columnName }) => + `${schemaName}${IndexName}${TableName}${columnName}`; + +const getUniqueIndexesColumns = ({ indexesColumns }) => { + const uniqueKeysToColumns = {}; + + for (const indexesColumn of indexesColumns) { + const columnKey = getColumnUniqueKey(indexesColumn); + const isColumnUnique = !uniqueKeysToColumns[columnKey]; + + if (!isColumnUnique) { + continue; + } + + uniqueKeysToColumns[columnKey] = indexesColumn; + } + + return Object.values(uniqueKeysToColumns); +}; + +module.exports = { + getUniqueIndexesColumns, +}; diff --git a/reverse_engineering/reverseEngineeringService/reverseEngineeringService.js b/reverse_engineering/reverseEngineeringService/reverseEngineeringService.js index e025d58..494880b 100644 --- a/reverse_engineering/reverseEngineeringService/reverseEngineeringService.js +++ b/reverse_engineering/reverseEngineeringService/reverseEngineeringService.js @@ -42,6 +42,7 @@ const { getPeriodForSystemTime, } = require('./helpers'); const pipe = require('../helpers/pipe'); +const { getUniqueIndexesColumns } = require('./helpers/getUniqueIndexesColumns'); const mergeCollectionsWithViews = ({ jsonSchemas }) => { const [viewSchemas, collectionSchemas] = partition(jsonSchemas, jsonSchema => jsonSchema.relatedTables); @@ -309,7 +310,8 @@ const reverseCollectionsToJSON = logger => async (dbConnectionClient, tablesInfo rawDatabaseIndexes.map(i => i.index_id), logger, ); - const databaseIndexes = addTotalBucketCountToDatabaseIndexes(rawDatabaseIndexes, indexesBucketCount); + const uniqueDatabaseIndexesColumns = getUniqueIndexesColumns({ indexesColumns: rawDatabaseIndexes }); + const databaseIndexes = addTotalBucketCountToDatabaseIndexes(uniqueDatabaseIndexesColumns, indexesBucketCount); return await Object.entries(tablesInfo).reduce(async (jsonSchemas, [schemaName, tableNames]) => { logger.log('info', { message: `Fetching '${dbName}' database information` }, 'Reverse Engineering');