Skip to content

Commit

Permalink
HCK-5388: fixed issue with not generated alter script for index on ex…
Browse files Browse the repository at this point in the history
…isting column (#99)
  • Loading branch information
WilhelmWesser authored Apr 19, 2024
1 parent 273ad8c commit 34ffada
Showing 1 changed file with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
};
Expand Down Expand Up @@ -133,23 +133,24 @@ 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)
};

/**
*
* @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 []
Expand Down

0 comments on commit 34ffada

Please sign in to comment.