Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}