Skip to content

Commit

Permalink
Hck-5358 HCK-5359: Double "Create Index" statement (all cases: new/ex…
Browse files Browse the repository at this point in the history
…isting entities) in ALTER script (#86)

* HCK-5358: removed redundant indexes script generation and removed redundant indexes source on indexes seelction for create index script generation

* HCK-5358: removed redundant indexes source for check
  • Loading branch information
WilhelmWesser authored Apr 18, 2024
1 parent 9cdaf9b commit 52c55a5
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
4 changes: 2 additions & 2 deletions forward_engineering/alterScript/alterScriptFromDeltaHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,18 +90,18 @@ const getAlterCollectionsScriptDtos = ({

const createCollectionsScriptDtos = createScriptsData.filter(collection => collection.compMod?.created).map(getAddCollectionScriptDto({app, dbVersion, modelDefinitions, internalDefinitions, externalDefinitions}));
const deleteCollectionScriptDtos = deleteScriptsData.filter(collection => collection.compMod?.deleted).map(getDeleteCollectionScriptDto(app));
const modifyCollectionsScriptDtos = modifyScriptsData.filter(collection => collection.compMod?.modified).flatMap(getModifyCollectionScriptDtos({app, dbVersion}))
const modifyCollectionScriptDtos = modifyScriptsData.filter(collection => collection.compMod?.modified).flatMap(getModifyCollectionScriptDtos({app, dbVersion}))
const addColumnScriptDtos = createScriptsData.filter(item => !item?.compMod?.created).flatMap(getAddColumnScriptDtos({app, dbVersion, modelDefinitions, internalDefinitions, externalDefinitions}));
const deleteColumnScriptDtos = deleteScriptsData.filter(item => !item?.compMod?.deleted).flatMap(getDeleteColumnScriptDtos(app));
const modifyColumnScriptDtos = modifyScriptsData.flatMap(getModifyColumnScriptDtos(app, dbVersion));

return [
...createCollectionsScriptDtos,
...deleteCollectionScriptDtos,
...modifyCollectionScriptDtos,
...addColumnScriptDtos,
...deleteColumnScriptDtos,
...modifyColumnScriptDtos,
...modifyCollectionsScriptDtos,
].filter(Boolean);
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const {AlterScriptDto} = require("../types/AlterScriptDto");
const {getUpdateTypesScriptDtos} = require("./columnHelpers/alterTypeHelper");
const {getRenameColumnScriptDtos} = require("./columnHelpers/renameColumnHelper");
const { getModifyIndexesScriptDtos } = require("./entityHelpers/indexesHelper");
const { getModifyIndexesScriptDtos, getAddedIndexesScriptDtos } = require("./entityHelpers/indexesHelper");

/**
* @return {(collection: AlterCollectionDto) => AlterScriptDto | undefined}
Expand Down Expand Up @@ -131,7 +131,7 @@ const getAddColumnScriptDtos =
* @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) {
Expand All @@ -144,7 +144,7 @@ const getIndexesBasedOnNewlyCreatedColumnsScript = ({_, ddlProvider, dbVersion,
return []
}

return getModifyIndexesScriptDtos({ _, ddlProvider })({ collection, dbVersion })
return getAddedIndexesScriptDtos({ _, ddlProvider })({ collection })
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ const getDeleteIndexScriptDto =
const getAddedIndexesScriptDtos =
({ _, ddlProvider }) =>
({ collection }) => {
const newIndexes = collection?.role?.compMod?.Indxs?.new || collection?.role?.Indxs || [];
const newIndexes = collection?.role?.Indxs || [];
const oldIndexes = collection?.role?.compMod?.Indxs?.old || [];

const addedIndexes = newIndexes.filter(newIndex => {
Expand Down Expand Up @@ -276,4 +276,5 @@ const getModifyIndexesScriptDtos =

module.exports = {
getModifyIndexesScriptDtos,
getAddedIndexesScriptDtos,
};

0 comments on commit 52c55a5

Please sign in to comment.