From 3292af915e191bc81082327275571a4f3f6b0d2a Mon Sep 17 00:00:00 2001 From: Nazar Kovtun Date: Thu, 18 Apr 2024 15:38:37 +0300 Subject: [PATCH 1/3] HCK-5356: removed invalid indexes source for new indexes and removed redundant indexes scripts generation on newly created columns --- .../alterScriptHelpers/alterEntityHelper.js | 14 ++++++++++++-- .../entityHelpers/indexesHelper.js | 3 ++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/forward_engineering/alterScript/alterScriptHelpers/alterEntityHelper.js b/forward_engineering/alterScript/alterScriptHelpers/alterEntityHelper.js index 15b4426..bbafefc 100644 --- a/forward_engineering/alterScript/alterScriptHelpers/alterEntityHelper.js +++ b/forward_engineering/alterScript/alterScriptHelpers/alterEntityHelper.js @@ -7,7 +7,7 @@ const {getRenameColumnScriptDtos} = require("./columnHelpers/renameColumnHelper" const {AlterScriptDto} = require("../types/AlterScriptDto"); const {AlterCollectionDto} = require('../types/AlterCollectionDto'); const {getModifyPkConstraintsScriptDtos} = require("./entityHelpers/primaryKeyHelper"); -const {getModifyIndexesScriptDtos} = require("./entityHelpers/indexesHelper"); +const {getModifyIndexesScriptDtos, getAddedIndexesScriptDtos} = require("./entityHelpers/indexesHelper"); /** @@ -155,7 +155,17 @@ const getIndexesBasedOnNewlyCreatedColumnsScript = ({_, ddlProvider, dbVersion, return [] } - return getModifyIndexesScriptDtos({ _, ddlProvider })({ collection, dbVersion }) + const {getSchemaNameFromCollection} = require('../../utils/general')(_); + const additionalDataForDdlProvider = { + dbData: {dbVersion}, + tableName: collection?.compMod?.collectionName?.new || collection?.role?.name || '', + schemaName: getSchemaNameFromCollection({collection}) || '', + isParentActivated: collection.isActivated, + } + + return getAddedIndexesScriptDtos({_, ddlProvider})({ + collection, additionalDataForDdlProvider + }); } /** diff --git a/forward_engineering/alterScript/alterScriptHelpers/entityHelpers/indexesHelper.js b/forward_engineering/alterScript/alterScriptHelpers/entityHelpers/indexesHelper.js index b52f877..ed0e277 100644 --- a/forward_engineering/alterScript/alterScriptHelpers/entityHelpers/indexesHelper.js +++ b/forward_engineering/alterScript/alterScriptHelpers/entityHelpers/indexesHelper.js @@ -141,7 +141,7 @@ const getCreateIndexScriptDto = ({_, ddlProvider}) => ({index, collection, addit * }) => Array} * */ const getAddedIndexesScriptDtos = ({_, ddlProvider}) => ({collection, additionalDataForDdlProvider}) => { - const newIndexes = collection?.role?.compMod?.Indxs?.new || collection?.role?.Indxs || []; + const newIndexes = collection?.role?.Indxs || []; const oldIndexes = collection?.role?.compMod?.Indxs?.old || []; return newIndexes @@ -347,4 +347,5 @@ const getModifyIndexesScriptDtos = ({_, ddlProvider}) => ({collection, dbVersion module.exports = { getModifyIndexesScriptDtos, + getAddedIndexesScriptDtos } From d93365872221a9359cb70c75cc42a026e8139527 Mon Sep 17 00:00:00 2001 From: Nazar Kovtun Date: Thu, 18 Apr 2024 16:07:40 +0300 Subject: [PATCH 2/3] HCK-5356: removed redundant indexes source for check --- .../alterScript/alterScriptHelpers/alterEntityHelper.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/forward_engineering/alterScript/alterScriptHelpers/alterEntityHelper.js b/forward_engineering/alterScript/alterScriptHelpers/alterEntityHelper.js index bbafefc..a9e2005 100644 --- a/forward_engineering/alterScript/alterScriptHelpers/alterEntityHelper.js +++ b/forward_engineering/alterScript/alterScriptHelpers/alterEntityHelper.js @@ -142,7 +142,7 @@ const getAddColumnsByConditionScriptDtos = ({app, dbVersion, modelDefinitions, * @return {AlterScriptDto[]} * */ const getIndexesBasedOnNewlyCreatedColumnsScript = ({_, ddlProvider, dbVersion, collection}) => { - const newIndexes = collection?.role?.compMod?.Indxs?.new || collection?.role?.Indxs || [] + const newIndexes = collection?.role?.Indxs || [] const newPropertiesIds = Object.values(collection?.properties ?? {}).map(({GUID}) => GUID) if (newIndexes.length === 0 || newPropertiesIds.length === 0) { From d4d0f16d7e8e138a492872224268987513e72fd0 Mon Sep 17 00:00:00 2001 From: Nazar Kovtun Date: Thu, 18 Apr 2024 16:28:48 +0300 Subject: [PATCH 3/3] HCK-5356: improved code --- .../alterScriptHelpers/alterEntityHelper.js | 10 ++------- .../entityHelpers/indexesHelper.js | 22 ++++++++++++------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/forward_engineering/alterScript/alterScriptHelpers/alterEntityHelper.js b/forward_engineering/alterScript/alterScriptHelpers/alterEntityHelper.js index a9e2005..e067325 100644 --- a/forward_engineering/alterScript/alterScriptHelpers/alterEntityHelper.js +++ b/forward_engineering/alterScript/alterScriptHelpers/alterEntityHelper.js @@ -7,7 +7,7 @@ const {getRenameColumnScriptDtos} = require("./columnHelpers/renameColumnHelper" const {AlterScriptDto} = require("../types/AlterScriptDto"); const {AlterCollectionDto} = require('../types/AlterCollectionDto'); const {getModifyPkConstraintsScriptDtos} = require("./entityHelpers/primaryKeyHelper"); -const {getModifyIndexesScriptDtos, getAddedIndexesScriptDtos} = require("./entityHelpers/indexesHelper"); +const {getModifyIndexesScriptDtos, getAddedIndexesScriptDtos, getAdditionalDataForDdlProvider} = require("./entityHelpers/indexesHelper"); /** @@ -155,13 +155,7 @@ const getIndexesBasedOnNewlyCreatedColumnsScript = ({_, ddlProvider, dbVersion, return [] } - const {getSchemaNameFromCollection} = require('../../utils/general')(_); - const additionalDataForDdlProvider = { - dbData: {dbVersion}, - tableName: collection?.compMod?.collectionName?.new || collection?.role?.name || '', - schemaName: getSchemaNameFromCollection({collection}) || '', - isParentActivated: collection.isActivated, - } + const additionalDataForDdlProvider = getAdditionalDataForDdlProvider({_, dbVersion, collection}) return getAddedIndexesScriptDtos({_, ddlProvider})({ collection, additionalDataForDdlProvider diff --git a/forward_engineering/alterScript/alterScriptHelpers/entityHelpers/indexesHelper.js b/forward_engineering/alterScript/alterScriptHelpers/entityHelpers/indexesHelper.js index ed0e277..1186546 100644 --- a/forward_engineering/alterScript/alterScriptHelpers/entityHelpers/indexesHelper.js +++ b/forward_engineering/alterScript/alterScriptHelpers/entityHelpers/indexesHelper.js @@ -319,13 +319,7 @@ const getModifiedIndexesScriptDtos = ({_, ddlProvider}) => ({collection, additio * @return {({ collection: AlterCollectionDto, dbVersion: string }) => Array} * */ const getModifyIndexesScriptDtos = ({_, ddlProvider}) => ({collection, dbVersion}) => { - const {getSchemaNameFromCollection} = require('../../../utils/general')(_); - const additionalDataForDdlProvider = { - dbData: {dbVersion}, - tableName: collection?.compMod?.collectionName?.new || collection?.role?.name || '', - schemaName: getSchemaNameFromCollection({collection}) || '', - isParentActivated: collection.isActivated, - } + const additionalDataForDdlProvider = getAdditionalDataForDdlProvider({_, dbVersion, collection}) const deletedIndexesScriptDtos = getDeletedIndexesScriptDtos({_, ddlProvider})({ collection, additionalDataForDdlProvider @@ -345,7 +339,19 @@ const getModifyIndexesScriptDtos = ({_, ddlProvider}) => ({collection, dbVersion .filter(Boolean); } +const getAdditionalDataForDdlProvider = ({_, dbVersion, collection}) => { + const {getSchemaNameFromCollection} = require('../../../utils/general')(_); + + return { + dbData: {dbVersion}, + tableName: collection?.compMod?.collectionName?.new || collection?.role?.name || '', + schemaName: getSchemaNameFromCollection({collection}) || '', + isParentActivated: collection.isActivated, + } +} + module.exports = { getModifyIndexesScriptDtos, - getAddedIndexesScriptDtos + getAddedIndexesScriptDtos, + getAdditionalDataForDdlProvider }