Skip to content

Commit

Permalink
modify migration file to work for Laravel 9+
Browse files Browse the repository at this point in the history
  • Loading branch information
mjauvin committed Apr 8, 2024
1 parent 6e3402d commit ab1cc3e
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions updates/v2.0.1/rename_indexes.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

0 comments on commit ab1cc3e

Please sign in to comment.