Skip to content

Commit 9e3c7b4

Browse files
committed
fix migration for Laravel > 9
1 parent 519500c commit 9e3c7b4

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

updates/v2.0.1/rename_indexes.php

+20-9
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,30 @@ public function down()
3131

3232
public function updateIndexNames($from, $to, $table)
3333
{
34-
$sm = Schema::getConnection()->getDoctrineSchemaManager();
34+
Schema::table($table, function ($blueprint) use ($from, $to) {
35+
foreach ($this->getIndexes($blueprint) as $index) {
36+
if (is_object($index) ? $index->isPrimary() : $index['primary']) {
37+
continue;
38+
}
3539

36-
$table = $sm->listTableDetails($table);
40+
$old = is_object($index) ? $index->getName() : $index['name'];
41+
$new = str_replace($from, $to, $old);
3742

38-
foreach ($table->getIndexes() as $index) {
39-
if ($index->isPrimary()) {
40-
continue;
43+
$blueprint->renameIndex($old, $new);
4144
}
45+
});
46+
}
4247

43-
$old = $index->getName();
44-
$new = str_replace($from, $to, $old);
45-
46-
$table->renameIndex($old, $new);
48+
public function getIndexes($blueprint)
49+
{
50+
$connection = Schema::getConnection();
51+
$table = $blueprint->getTable();
52+
53+
if (method_exists($connection, 'getDoctrineSchemaManager')) {
54+
$sm = $connection->getDoctrineSchemaManager();
55+
return $sm->listTableDetails($table)->getIndexes();
56+
} else {
57+
return $connection->getSchemaBuilder()->getIndexes($table);
4758
}
4859
}
4960
}

0 commit comments

Comments
 (0)