@@ -172,45 +172,41 @@ const getDeleteColumnScriptDtos = app => collection => {
172172 return getDeleteColumnsByConditionScriptDtos ( app ) ( collection , ( [ name , jsonSchema ] ) => ! jsonSchema . compMod )
173173} ;
174174
175- const getModifyGeneratedColumnsScriptDtos = ( { app, dbVersion, modelDefinitions, internalDefinitions, externalDefinitions} ) =>
176- ( collection ) => {
177- const _ = app . require ( 'lodash' ) ;
178-
179- return _ . toPairs ( collection . properties )
180- . filter ( ( [ name , jsonSchema ] ) => {
181- const oldName = jsonSchema . compMod . oldField . name ;
182- const oldProperty = collection . role . properties [ oldName ] ;
183-
184- return oldProperty . generatedColumn !== jsonSchema . generatedColumn
185- || oldProperty . columnGenerationExpression !== jsonSchema . columnGenerationExpression ;
186- } )
187- . flatMap ( ( [ name , jsonSchema ] ) => {
188- const collectionWithJustThisProperty = {
189- ...collection ,
190- properties : _ . fromPairs ( [
191- [ name , jsonSchema ]
192- ] ) ,
193- }
194- const deleteColumnsScriptDtos = getDeleteColumnsByConditionScriptDtos ( app ) ( collectionWithJustThisProperty , ( ) => true ) ;
195- const addColumnsScriptDtos = getAddColumnsByConditionScriptDtos ( {
196- app, dbVersion, modelDefinitions, internalDefinitions, externalDefinitions
197- } ) ( collectionWithJustThisProperty , ( ) => true ) ;
198-
199- return [
200- ...deleteColumnsScriptDtos ,
201- ...addColumnsScriptDtos ,
202- ]
203- } )
204- . filter ( Boolean ) ;
205- }
206-
175+ /**
176+ * @return {(collection: Object) => Array<AlterScriptDto> }
177+ * */
207178const getDropAndRecreateColumnsScriptDtos = ( { app, dbVersion, modelDefinitions, internalDefinitions, externalDefinitions} ) =>
208179 ( collection ) => {
209- const modifyGeneratedColumnsScriptDtos = getModifyGeneratedColumnsScriptDtos ( { app, dbVersion , modelDefinitions , internalDefinitions , externalDefinitions } ) ( collection ) ;
180+ const _ = app . require ( 'lodash' ) ;
210181
211- return [
212- ...modifyGeneratedColumnsScriptDtos ,
213- ]
182+ return _ . toPairs ( collection . properties )
183+ . filter ( ( [ name , jsonSchema ] ) => {
184+ const oldName = jsonSchema . compMod . oldField . name ;
185+ const oldProperty = collection . role . properties [ oldName ] ;
186+
187+ const didGeneratedColumnChange = oldProperty . generatedColumn !== jsonSchema . generatedColumn
188+ || oldProperty . columnGenerationExpression !== jsonSchema . columnGenerationExpression ;
189+ // all conditions that require drop-and-recreate go here
190+ return didGeneratedColumnChange ;
191+ } )
192+ . flatMap ( ( [ name , jsonSchema ] ) => {
193+ const collectionWithJustThisProperty = {
194+ ...collection ,
195+ properties : _ . fromPairs ( [
196+ [ name , jsonSchema ]
197+ ] ) ,
198+ }
199+ const deleteColumnsScriptDtos = getDeleteColumnsByConditionScriptDtos ( app ) ( collectionWithJustThisProperty , ( ) => true ) ;
200+ const addColumnsScriptDtos = getAddColumnsByConditionScriptDtos ( {
201+ app, dbVersion, modelDefinitions, internalDefinitions, externalDefinitions
202+ } ) ( collectionWithJustThisProperty , ( ) => true ) ;
203+
204+ return [
205+ ...deleteColumnsScriptDtos ,
206+ ...addColumnsScriptDtos ,
207+ ]
208+ } )
209+ . filter ( Boolean ) ;
214210 }
215211
216212/**
0 commit comments