Skip to content

Commit

Permalink
HCK-5356: Double "Create Index" and "Drop Index" statement in existin…
Browse files Browse the repository at this point in the history
…g 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
  • Loading branch information
WilhelmWesser authored Apr 18, 2024
1 parent 0e823e8 commit 273ad8c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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");


/**
Expand Down Expand Up @@ -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) {
Expand All @@ -155,7 +155,11 @@ const getIndexesBasedOnNewlyCreatedColumnsScript = ({_, ddlProvider, dbVersion,
return []
}

return getModifyIndexesScriptDtos({ _, ddlProvider })({ collection, dbVersion })
const additionalDataForDdlProvider = getAdditionalDataForDdlProvider({_, dbVersion, collection})

return getAddedIndexesScriptDtos({_, ddlProvider})({
collection, additionalDataForDdlProvider
});
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ const getCreateIndexScriptDto = ({_, ddlProvider}) => ({index, collection, addit
* }) => Array<AlterScriptDto>}
* */
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
Expand Down Expand Up @@ -319,13 +319,7 @@ const getModifiedIndexesScriptDtos = ({_, ddlProvider}) => ({collection, additio
* @return {({ collection: AlterCollectionDto, dbVersion: string }) => Array<AlterScriptDto>}
* */
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
Expand All @@ -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
}

0 comments on commit 273ad8c

Please sign in to comment.