diff --git a/updates/v2.0.1/rename_indexes.php b/updates/v2.0.1/rename_indexes.php index 88e7f12..fa6035e 100755 --- a/updates/v2.0.1/rename_indexes.php +++ b/updates/v2.0.1/rename_indexes.php @@ -32,19 +32,30 @@ public function down() public function updateIndexNames($from, $to, $table) { - $sm = Schema::getConnection()->getDoctrineSchemaManager(); + Schema::table($table, function ($blueprint) use ($from, $to) { + foreach ($this->getIndexes($blueprint) as $index) { + if (is_object($index) ? $index->isPrimary() : $index['primary']) { + continue; + } - $table = $sm->listTableDetails($table); + $old = is_object($index) ? $index->getName() : $index['name']; + $new = str_replace($from, $to, $old); - foreach ($table->getIndexes() as $index) { - if ($index->isPrimary()) { - continue; + $blueprint->renameIndex($old, $new); } + }); + } - $old = $index->getName(); - $new = str_replace($from, $to, $old); - - $table->renameIndex($old, $new); + public function getIndexes($blueprint) + { + $connection = Schema::getConnection(); + $table = $blueprint->getTable(); + + if (method_exists($connection, 'getDoctrineSchemaManager')) { + $sm = $connection->getDoctrineSchemaManager(); + return $sm->listTableDetails($table)->getIndexes(); + } else { + return $connection->getSchemaBuilder()->getIndexes($table); } } }