Skip to content

Commit

Permalink
HCK-7953: fix creation of indexes on added view in alter script (#107)
Browse files Browse the repository at this point in the history
* HCK-7953: fix creation of indexes on added view in alter script

* fix typos
  • Loading branch information
Vitalii4as authored Sep 18, 2024
1 parent 1a35818 commit 7fb3f5c
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions forward_engineering/helpers/alterScriptHelpers/alterViewHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 7fb3f5c

Please sign in to comment.