From 273ad8cfae6c1cbcf2933b5c8706004023ce0826 Mon Sep 17 00:00:00 2001 From: Nazar Kovtun <88377450+WilhelmWesser@users.noreply.github.com> Date: Thu, 18 Apr 2024 16:29:40 +0300 Subject: [PATCH] HCK-5356: Double "Create Index" and "Drop Index" statement in existing entities in ALTER script (#98) * HCK-5356: removed invalid indexes source for new indexes and removed redundant indexes scripts generation on newly created columns * HCK-5356: removed redundant indexes source for check * HCK-5356: improved code --- .../alterScriptHelpers/alterEntityHelper.js | 10 +++++--- .../entityHelpers/indexesHelper.js | 23 ++++++++++++------- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/forward_engineering/alterScript/alterScriptHelpers/alterEntityHelper.js b/forward_engineering/alterScript/alterScriptHelpers/alterEntityHelper.js index 15b4426..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} = require("./entityHelpers/indexesHelper"); +const {getModifyIndexesScriptDtos, getAddedIndexesScriptDtos, getAdditionalDataForDdlProvider} = require("./entityHelpers/indexesHelper"); /** @@ -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) { @@ -155,7 +155,11 @@ const getIndexesBasedOnNewlyCreatedColumnsScript = ({_, ddlProvider, dbVersion, return [] } - return getModifyIndexesScriptDtos({ _, ddlProvider })({ collection, dbVersion }) + 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 b52f877..1186546 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 @@ -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,6 +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, + getAdditionalDataForDdlProvider }