@@ -553,55 +553,44 @@ const sortScript = (scriptData) => {
553
553
554
554
return scripts ;
555
555
} , { scripts : [ ] , filteredScripts : [ ] } ) ;
556
- }
556
+ } ;
557
+
558
+ const orderForScripts = [
559
+ [ 'keySpaces' , 'added' ] ,
560
+ [ 'keySpaces' , 'modified' ] ,
561
+ [ 'view' , 'deleted' ] ,
562
+ [ 'index' , 'deleted' ] ,
563
+ [ 'renewal' , 'deleted' ] ,
564
+ [ 'table' , 'deleted' ] ,
565
+ [ 'udt' , 'deleted' ] ,
566
+ [ 'udt' , 'added' ] ,
567
+ [ 'udt' , 'modified' ] ,
568
+ [ 'table' , 'added' ] ,
569
+ [ 'table' , 'modified' ] ,
570
+ [ 'field' , 'deleted' ] ,
571
+ [ 'field' , 'added' ] ,
572
+ [ 'field' , 'modified' ] ,
573
+ [ 'index' , 'added' ] ,
574
+ [ 'index' , 'modified' ] ,
575
+ [ 'renewal' , 'added' ] ,
576
+ [ 'view' , 'added' ] ,
577
+ [ 'view' , 'modified' ] ,
578
+ [ 'udf' , 'deleted' ] ,
579
+ [ 'udf' , 'added' ] ,
580
+ [ 'keySpaces' , 'deleted' ] ,
581
+ ] ;
582
+ const sortedScripts = orderForScripts . reduce ( ( script , [ key , prop ] ) => {
583
+ const { scripts, filteredScripts } = filter ( prop , script . filteredScripts , key ) ;
584
+ return {
585
+ sorted : [ ...script . sorted , ...scripts ] ,
586
+ filteredScripts
587
+ }
588
+ } , {
589
+ sorted : [ ] ,
590
+ filteredScripts : scriptData
591
+ } ) ;
557
592
558
- let sortedScripts = [ ] ;
559
-
560
- const { scripts : createKeyspacesScripts , filteredScripts : scriptsWithoutCreateKeyspace } = filter ( 'added' , scriptData , 'keySpaces' ) ;
561
- const { scripts : deleteKeyspaceScripts , filteredScripts : scriptsWithoutDropKeyspace } = filter ( 'deleted' , scriptsWithoutCreateKeyspace , 'keySpaces' ) ;
562
- const { scripts : modifyKeyspacesScripts , filteredScripts : scriptsWithoutModifyKeyspace } = filter ( 'modified' , scriptsWithoutDropKeyspace , 'keySpaces' ) ;
563
- const { scripts : deleteFunctionScripts , filteredScripts : scriptsWithoutDropFunction } = filter ( 'deleted' , scriptsWithoutModifyKeyspace , 'udf' ) ;
564
- const { scripts : createFunctionScripts , filteredScripts : scriptsWithoutCreateFunction } = filter ( 'added' , scriptsWithoutDropFunction , 'udf' ) ;
565
- const { scripts : createTablesScripts , filteredScripts : scriptsWithoutCreateTable } = filter ( 'added' , scriptsWithoutCreateFunction , 'table' ) ;
566
- const { scripts : deleteTablesScripts , filteredScripts : scriptsWithoutDropTable } = filter ( 'deleted' , scriptsWithoutCreateTable , 'table' ) ;
567
- const { scripts : modifyTablesScripts , filteredScripts : scriptsWithoutModifyTable } = filter ( 'modified' , scriptsWithoutDropTable , 'table' ) ;
568
- const { scripts : createIndexesScripts , filteredScripts : scriptsWithoutCreateIndexes } = filter ( 'added' , scriptsWithoutModifyTable , 'index' ) ;
569
- const { scripts : deleteIndexesScripts , filteredScripts : scriptsWithoutDropIndexes } = filter ( 'deleted' , scriptsWithoutCreateIndexes , 'index' ) ;
570
- const { scripts : modifyIndexesScripts , filteredScripts : scriptsWithoutModifyIndexes } = filter ( 'modified' , scriptsWithoutDropIndexes , 'index' ) ;
571
- const { scripts : renewalIndexesScripts , filteredScripts : scriptsWithoutRenewalIndexes } = filter ( 'added' , scriptsWithoutModifyIndexes , 'renewal' ) ;
572
- const { scripts : createViewsScripts , filteredScripts : scriptsWithoutCreateViews } = filter ( 'added' , scriptsWithoutRenewalIndexes , 'viewName' ) ;
573
- const { scripts : deleteViewsScripts , filteredScripts : scriptsWithoutDeleteViews } = filter ( 'deleted' , scriptsWithoutCreateViews , 'viewName' ) ;
574
- const { scripts : modifyViewsScripts , filteredScripts : scriptsWithoutModifyViews } = filter ( 'modified' , scriptsWithoutDeleteViews , 'viewName' ) ;
575
- const { scripts : createFieldsScripts , filteredScripts : scriptsWithoutCreateField } = filter ( 'added' , scriptsWithoutModifyViews , 'field' ) ;
576
- const { scripts : deleteFieldsScripts , filteredScripts : scriptsWithoutDeleteField } = filter ( 'deleted' , scriptsWithoutCreateField , 'field' ) ;
577
- const { scripts : modifyFieldsScripts , filteredScripts : scriptsWithoutModifyField } = filter ( 'modified' , scriptsWithoutDeleteField , 'field' ) ;
578
- const { scripts : createUdtScripts , filteredScripts : scriptsWithoutCreateUdt } = filter ( 'added' , scriptsWithoutModifyField , 'udtName' ) ;
579
- const { scripts : deleteUdtScripts , filteredScripts : scriptsWithoutDeleteUdt } = filter ( 'deleted' , scriptsWithoutCreateUdt , 'udtName' ) ;
580
- const { scripts : modifyUdtScripts , filteredScripts : scriptsWithoutModifyUdt } = filter ( 'modified' , scriptsWithoutDeleteUdt , 'udtName' ) ;
581
-
582
- return sortedScripts . concat (
583
- createKeyspacesScripts ,
584
- modifyKeyspacesScripts ,
585
- deleteViewsScripts ,
586
- deleteTablesScripts ,
587
- deleteUdtScripts ,
588
- createUdtScripts ,
589
- modifyUdtScripts ,
590
- createTablesScripts ,
591
- modifyTablesScripts ,
592
- deleteFieldsScripts ,
593
- createFieldsScripts ,
594
- modifyFieldsScripts ,
595
- deleteIndexesScripts ,
596
- createIndexesScripts ,
597
- modifyIndexesScripts ,
598
- createViewsScripts ,
599
- modifyViewsScripts ,
600
- renewalIndexesScripts ,
601
- deleteFunctionScripts ,
602
- createFunctionScripts ,
603
- deleteKeyspaceScripts ,
604
- scriptsWithoutModifyUdt ) . map ( data => data . script ) ;
593
+ return [ ...sortedScripts . sorted , ...sortedScripts . filteredScripts ] . map ( data => data . script ) ;
605
594
}
606
595
607
596
module . exports = {
0 commit comments