@@ -314,7 +314,7 @@ public function transAlterField($table, $field, $schema)
314314 *
315315 * @param string $table Name of the table to hold this index
316316 * @param string $index Name of the index to update
317- * @param array $schema Already parsed index specification
317+ * @param array|false $schema Already parsed index specification, or false to drop the index.
318318 */
319319 public function transAlterIndex ($ table , $ index , $ schema )
320320 {
@@ -431,7 +431,11 @@ public function requireTable(
431431 // Create custom indexes
432432 if ($ indexSchema ) {
433433 foreach ($ indexSchema as $ indexName => $ indexSpec ) {
434- $ this ->requireIndex ($ table , $ indexName , $ indexSpec );
434+ if ($ indexSpec === false ) {
435+ $ this ->dontRequireIndex ($ table , $ indexName );
436+ } else {
437+ $ this ->requireIndex ($ table , $ indexName , $ indexSpec );
438+ }
435439 }
436440 }
437441
@@ -529,6 +533,28 @@ public function requireIndex($table, $index, $spec)
529533 }
530534 }
531535
536+ public function dontRequireIndex (string $ table , string $ index ): void
537+ {
538+ // Skip if this is a new table, since it just won't have that index
539+ $ newTable = !isset ($ this ->tableList [strtolower ($ table )]);
540+ if ($ newTable ) {
541+ return ;
542+ }
543+
544+ $ indexKey = $ this ->indexKey ($ table , $ index , []);
545+ $ indexList = $ this ->indexList ($ table );
546+ // Drop the index if it exists
547+ if (isset ($ indexList [$ indexKey ])) {
548+ $ oldSpec = $ indexList [$ indexKey ];
549+ $ oldSpecString = $ this ->convertIndexSpec ($ oldSpec );
550+ $ this ->transAlterIndex ($ table , $ index , false );
551+ $ this ->alterationMessage (
552+ "Index $ table. $ index: dropped <i class= \"build-info-before \">(from $ oldSpecString)</i> " ,
553+ "deleted "
554+ );
555+ }
556+ }
557+
532558 /**
533559 * Splits a spec string safely, considering quoted columns, whitespace,
534560 * and cleaning brackets
0 commit comments