From 7fb3f5cda9a3ff99c62086114a9326ab9b1baef9 Mon Sep 17 00:00:00 2001 From: Vitalii Yarmus <71256742+Vitalii4as@users.noreply.github.com> Date: Wed, 18 Sep 2024 11:56:47 +0300 Subject: [PATCH] HCK-7953: fix creation of indexes on added view in alter script (#107) * HCK-7953: fix creation of indexes on added view in alter script * fix typos --- .../alterScriptHelpers/alterViewHelper.js | 37 ++++++++++++++++++- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/forward_engineering/helpers/alterScriptHelpers/alterViewHelper.js b/forward_engineering/helpers/alterScriptHelpers/alterViewHelper.js index c2d4e9a..8ab8fd4 100644 --- a/forward_engineering/helpers/alterScriptHelpers/alterViewHelper.js +++ b/forward_engineering/helpers/alterScriptHelpers/alterViewHelper.js @@ -8,16 +8,29 @@ module.exports = (app, options) => { const { AlterScriptDto } = require('./types/AlterScriptDto'); const getAddViewScriptDto = view => { + const viewName = getTableName(view.code || view.name, view?.role?.compMod?.keyspaceName); const viewSchema = { ...view, ...(view.role ?? {}) }; + const idToNameHashTable = generateRefToNameHashTable(viewSchema); + const idToActivatedHashTable = generateRefToActivatedHashTable(viewSchema); + const schemaData = { schemaName: viewSchema.compMod.keyspaceName }; const viewData = { name: viewSchema.code || viewSchema.name, keys: getKeys(viewSchema, viewSchema.compMod?.collectionData?.collectionRefsDefinitionsMap ?? {}), - schemaData: { schemaName: viewSchema.compMod.keyspaceName }, + schemaData, }; const hydratedView = ddlProvider.hydrateView({ viewData, entityData: [view] }); - return AlterScriptDto.getInstance([ddlProvider.createView(hydratedView, {}, view.isActivated)], true, false); + const viewScript = AlterScriptDto.getInstance( + [ddlProvider.createView(hydratedView, {}, view.isActivated)], + true, + false, + ); + const indexesSCripts = (viewSchema.Indxs || []) + .map(hydrateIndex({ idToNameHashTable, idToActivatedHashTable, schemaData })) + .map(index => AlterScriptDto.getInstance([ddlProvider.createViewIndex(viewName, index)], true, false)); + + return [viewScript, ...indexesSCripts].filter(Boolean); }; const getDeleteViewScriptDto = view => { @@ -178,6 +191,26 @@ module.exports = (app, options) => { .filter(Boolean); }; + const generateRefToNameHashTable = view => { + const refToNameHashTable = {}; + + mapProperties(view, (propertyName, schema) => { + refToNameHashTable[schema.ref] = propertyName; + }); + + return refToNameHashTable; + }; + + const generateRefToActivatedHashTable = view => { + const refToActivatedHashTable = {}; + + mapProperties(view, (propertyName, schema) => { + refToActivatedHashTable[schema.ref] = schema.isActivated; + }); + + return refToActivatedHashTable; + }; + return { getAddViewScriptDto, getDeleteViewScriptDto,