@@ -56,7 +56,7 @@ const getAddCollectionScriptDto =
5656 } ;
5757 const hydratedTable = ddlProvider . hydrateTable ( { tableData, entityData : [ jsonSchema ] , jsonSchema} ) ;
5858
59- const indexesOnNewlyCreatedColumnsScripts = getIndexesBasedOnNewlyCreatedColumnsScript ( { _, ddlProvider, collection, dbVersion} ) . flatMap ( ( { scripts} ) => scripts . map ( ( { script} ) => script ) )
59+ const indexesOnNewlyCreatedColumnsScripts = getNewlyCreatedIndexesScripts ( { _, ddlProvider, collection, dbVersion} ) . flatMap ( ( { scripts} ) => scripts . map ( ( { script} ) => script ) )
6060 const script = ddlProvider . createTable ( hydratedTable , jsonSchema . isActivated ) ;
6161 return AlterScriptDto . getInstance ( [ script , ...indexesOnNewlyCreatedColumnsScripts ] , true , false )
6262 } ;
@@ -133,23 +133,24 @@ const getAddColumnsByConditionScriptDtos = ({app, dbVersion, modelDefinitions,
133133 . map ( columnDefinition => ddlProvider . addColumn ( fullName , columnDefinition ) )
134134 . map ( addColumnScript => AlterScriptDto . getInstance ( [ addColumnScript ] , true , false ) ) ;
135135
136- const indexesOnNewlyCreatedColumns = getIndexesBasedOnNewlyCreatedColumnsScript ( { _, ddlProvider, collection} )
136+ const indexesOnNewlyCreatedColumns = getNewlyCreatedIndexesScripts ( { _, ddlProvider, collection} )
137137 return scripts . concat ( indexesOnNewlyCreatedColumns ) . filter ( Boolean )
138138 } ;
139139
140140/**
141141 *
142142 * @return {AlterScriptDto[] }
143143 * */
144- const getIndexesBasedOnNewlyCreatedColumnsScript = ( { _, ddlProvider, dbVersion, collection} ) => {
144+ const getNewlyCreatedIndexesScripts = ( { _, ddlProvider, dbVersion, collection} ) => {
145145 const newIndexes = collection ?. role ?. Indxs || [ ]
146- const newPropertiesIds = Object . values ( collection ?. properties ?? { } ) . map ( ( { GUID } ) => GUID )
146+ const properties = { ...( collection ?. properties ) , ...( collection ?. role ?. properties ) }
147+ const propertiesIds = Object . values ( properties ) . map ( ( { GUID } ) => GUID )
147148
148- if ( newIndexes . length === 0 || newPropertiesIds . length === 0 ) {
149+ if ( newIndexes . length === 0 || propertiesIds . length === 0 ) {
149150 return [ ]
150151 }
151152
152- const doAnyIndexUseNewlyCreatedColumn = newIndexes . some ( ( { columns} ) => columns . find ( ( { keyId} ) => newPropertiesIds . includes ( keyId ) ) )
153+ const doAnyIndexUseNewlyCreatedColumn = newIndexes . some ( ( { columns} ) => columns . find ( ( { keyId} ) => propertiesIds . includes ( keyId ) ) )
153154
154155 if ( ! doAnyIndexUseNewlyCreatedColumn ) {
155156 return [ ]
0 commit comments