@@ -96,6 +96,7 @@ class TableDefinition {
96
96
this . _getMigrateKeysOperations ( oldSchema , KEY_TYPES . UNIQUE , 'uniqueKeys' ) ,
97
97
this . _getMigrateKeysOperations ( oldSchema , KEY_TYPES . INDEX , 'indexes' ) ,
98
98
this . _getMigrateKeysOperations ( oldSchema , KEY_TYPES . SPATIAL , 'spatialIndexes' ) ,
99
+ this . _getDropUnknownKeysOperations ( oldSchema ) ,
99
100
this . _getMigrateTableOptionsOperations ( oldSchema )
100
101
) ;
101
102
const operations = this . _getMigrateForeignKeysOperations ( oldSchema , alterOperations ) ;
@@ -217,6 +218,21 @@ class TableDefinition {
217
218
return operations ;
218
219
}
219
220
221
+ _getDropUnknownKeysOperations ( oldSchema ) {
222
+ const operations = [ ] ;
223
+ const unknownKeys = oldSchema . $unknownKeys ;
224
+
225
+ for ( var i = 0 ; i < unknownKeys . length ; i ++ ) {
226
+ operations . push ( Operation . create (
227
+ Operation . Types . DROP_KEY ,
228
+ 'DROP KEY ' + this . _pool . escapeId ( unknownKeys [ i ] . name ) ,
229
+ unknownKeys [ i ] . columns
230
+ ) ) ;
231
+ }
232
+
233
+ return operations ;
234
+ }
235
+
220
236
_getMigrateForeignKeysOperations ( oldSchema , otherOperations ) {
221
237
const operations = [ ] ;
222
238
const oldForeignKeys = oldSchema . foreignKeys ;
@@ -582,6 +598,7 @@ function sqlToSchema(sql) {
582
598
indexes : generateKeysSchema ( createDefinitions , KEY_TYPES . INDEX ) ,
583
599
spatialIndexes : generateKeysSchema ( createDefinitions , KEY_TYPES . SPATIAL ) ,
584
600
foreignKeys : generateForegnKeysSchema ( createDefinitions ) ,
601
+ $unknownKeys : getUnknownKeys ( createDefinitions ) ,
585
602
} ;
586
603
587
604
let match = / E N G I N E = ( \w + ) / . exec ( tableOptions ) ;
@@ -712,13 +729,13 @@ function generateKeysSchema(createDefinitions, keyType) {
712
729
713
730
switch ( keyType ) {
714
731
case KEY_TYPES . UNIQUE :
715
- rgxKey = / ^ \s * U N I Q U E K E Y ` \w + ` \( ( .* ?) \) / ;
732
+ rgxKey = / ^ \s * U N I Q U E K E Y ` u n i q u e _ \w + ` \( ( .* ?) \) / ;
716
733
break ;
717
734
case KEY_TYPES . INDEX :
718
- rgxKey = / ^ \s * (?: I N D E X | K E Y ) ` \w + ` \( ( .* ?) \) / ;
735
+ rgxKey = / ^ \s * K E Y ` i n d e x _ \w + ` \( ( .* ?) \) / ;
719
736
break ;
720
737
case KEY_TYPES . SPATIAL :
721
- rgxKey = / ^ \s * S P A T I A L (?: I N D E X | K E Y ) ` \w + ` \( ( .* ?) \) / ;
738
+ rgxKey = / ^ \s * S P A T I A L K E Y ` s p a t i a l _ \w + ` \( ( .* ?) \) / ;
722
739
break ;
723
740
}
724
741
@@ -732,6 +749,24 @@ function generateKeysSchema(createDefinitions, keyType) {
732
749
return keys . length ? keys : null ;
733
750
}
734
751
752
+ function getUnknownKeys ( createDefinitions ) {
753
+ const keys = [ ] ;
754
+ const rgxKey =
755
+ / ^ \s * (?: U N I Q U E K E Y ` ( (? ! u n i q u e _ ) \w + ) ` | K E Y ` ( (? ! i n d e x _ ) \w + ) ` | S P A T I A L K E Y ` ( (? ! s p a t i a l _ ) \w + ) ` ) \( ( .* ?) \) / ;
756
+
757
+ for ( var i = 0 ; i < createDefinitions . length ; i ++ ) {
758
+ const keyMatch = rgxKey . exec ( createDefinitions [ i ] ) ;
759
+ if ( keyMatch ) {
760
+ keys . push ( {
761
+ name : keyMatch [ 1 ] || keyMatch [ 2 ] || keyMatch [ 3 ] ,
762
+ columns : columnsSQLToSchema ( keyMatch [ 4 ] ) ,
763
+ } ) ;
764
+ }
765
+ }
766
+
767
+ return keys ;
768
+ }
769
+
735
770
function generateForegnKeysSchema ( createDefinitions ) {
736
771
const foreignKeys = { } ;
737
772
const rgxForeignKey =
0 commit comments