@@ -142,13 +142,13 @@ const parseIndex = function(idx)
142142
143143 let options = { } ;
144144
145- if ( idx . name )
146- options . indexName = idx . name ; // The name of the index. Default is __
145+ if ( idx . name )
146+ options . name = options . indexName = idx . name ; // The name of the index. Default is __
147147
148148 // @todo : UNIQUE|FULLTEXT|SPATIAL
149- if ( idx . unique )
150- options . indicesType = 'UNIQUE' ;
151-
149+ if ( idx . unique )
150+ options . type = options . indicesType = 'UNIQUE' ;
151+
152152 if ( idx . method )
153153 options . indexType = idx . type ; // Set a type for the index, e.g. BTREE. See the documentation of the used dialect
154154
@@ -461,6 +461,42 @@ const parseDifference = function(previousState, currentState)
461461 depends : depends
462462 } ) ;
463463 }
464+
465+ // updated index
466+ // only support updating and dropping indexes
467+ if ( df . path [ 1 ] === 'indexes' )
468+ {
469+ let tableName = df . path [ 0 ] ;
470+ let keys = Object . keys ( df . rhs )
471+
472+ for ( let k in keys ) {
473+ let key = keys [ k ]
474+ let index = _ . clone ( df . rhs [ key ] ) ;
475+ actions . push ( {
476+ actionType : 'addIndex' ,
477+ tableName : tableName ,
478+ fields : df . rhs [ key ] . fields ,
479+ options : df . rhs [ key ] . options ,
480+ depends : [ tableName ]
481+ } ) ;
482+ break ;
483+ }
484+
485+ keys = Object . keys ( df . lhs )
486+ for ( let k in keys ) {
487+ let key = keys [ k ]
488+ let index = _ . clone ( df . lhs [ key ] ) ;
489+ actions . push ( {
490+ actionType : 'removeIndex' ,
491+ tableName : tableName ,
492+ fields : df . lhs [ key ] . fields ,
493+ options : df . lhs [ key ] . options ,
494+ depends : [ tableName ]
495+ } ) ;
496+ break ;
497+ }
498+ }
499+
464500 }
465501 break ;
466502
0 commit comments