From 34ffada34b2e5901bd9f07f67dd7b0f882f51ec8 Mon Sep 17 00:00:00 2001 From: Nazar Kovtun <88377450+WilhelmWesser@users.noreply.github.com> Date: Fri, 19 Apr 2024 16:33:02 +0300 Subject: [PATCH] HCK-5388: fixed issue with not generated alter script for index on existing column (#99) --- .../alterScriptHelpers/alterEntityHelper.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/forward_engineering/alterScript/alterScriptHelpers/alterEntityHelper.js b/forward_engineering/alterScript/alterScriptHelpers/alterEntityHelper.js index e067325..72227f0 100644 --- a/forward_engineering/alterScript/alterScriptHelpers/alterEntityHelper.js +++ b/forward_engineering/alterScript/alterScriptHelpers/alterEntityHelper.js @@ -56,7 +56,7 @@ const getAddCollectionScriptDto = }; const hydratedTable = ddlProvider.hydrateTable({tableData, entityData: [jsonSchema], jsonSchema}); - const indexesOnNewlyCreatedColumnsScripts = getIndexesBasedOnNewlyCreatedColumnsScript({_, ddlProvider, collection, dbVersion}).flatMap(({scripts}) => scripts.map(({script}) => script)) + const indexesOnNewlyCreatedColumnsScripts = getNewlyCreatedIndexesScripts({_, ddlProvider, collection, dbVersion}).flatMap(({scripts}) => scripts.map(({script}) => script)) const script = ddlProvider.createTable(hydratedTable, jsonSchema.isActivated); return AlterScriptDto.getInstance([script, ...indexesOnNewlyCreatedColumnsScripts], true, false) }; @@ -133,7 +133,7 @@ const getAddColumnsByConditionScriptDtos = ({app, dbVersion, modelDefinitions, .map(columnDefinition => ddlProvider.addColumn(fullName, columnDefinition)) .map(addColumnScript => AlterScriptDto.getInstance([addColumnScript], true, false)); - const indexesOnNewlyCreatedColumns = getIndexesBasedOnNewlyCreatedColumnsScript({_, ddlProvider, collection}) + const indexesOnNewlyCreatedColumns = getNewlyCreatedIndexesScripts({_, ddlProvider, collection}) return scripts.concat(indexesOnNewlyCreatedColumns).filter(Boolean) }; @@ -141,15 +141,16 @@ const getAddColumnsByConditionScriptDtos = ({app, dbVersion, modelDefinitions, * * @return {AlterScriptDto[]} * */ -const getIndexesBasedOnNewlyCreatedColumnsScript = ({_, ddlProvider, dbVersion, collection}) => { +const getNewlyCreatedIndexesScripts = ({_, ddlProvider, dbVersion, collection}) => { const newIndexes = collection?.role?.Indxs || [] - const newPropertiesIds = Object.values(collection?.properties ?? {}).map(({GUID}) => GUID) + const properties = {...(collection?.properties), ...(collection?.role?.properties)} + const propertiesIds = Object.values(properties).map(({GUID}) => GUID) - if (newIndexes.length === 0 || newPropertiesIds.length === 0) { + if (newIndexes.length === 0 || propertiesIds.length === 0) { return [] } - const doAnyIndexUseNewlyCreatedColumn = newIndexes.some(({columns}) => columns.find(({keyId}) => newPropertiesIds.includes(keyId))) + const doAnyIndexUseNewlyCreatedColumn = newIndexes.some(({columns}) => columns.find(({keyId}) => propertiesIds.includes(keyId))) if (!doAnyIndexUseNewlyCreatedColumn) { return []