Skip to content

Commit d8f38d8

Browse files
[12.x] Prioritize Current Schema When Resolving the Table Name in db:table Command (#56646)
* make db:table respect schemas search path * force re-run tests
1 parent 1effcff commit d8f38d8

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/Illuminate/Database/Console/TableCommand.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,17 @@ public function handle(ConnectionResolverInterface $connections)
4747
array_keys($tables)
4848
);
4949

50-
$table = $tables[$tableName] ?? Arr::first($tables, fn ($table) => $table['name'] === $tableName);
50+
$table = $tables[$tableName] ?? (new Collection($tables))->when(
51+
Arr::wrap($connection->getSchemaBuilder()->getCurrentSchemaListing()
52+
?? $connection->getSchemaBuilder()->getCurrentSchemaName()),
53+
fn (Collection $collection, array $currentSchemas) => $collection->sortBy(
54+
function (array $table) use ($currentSchemas) {
55+
$index = array_search($table['schema'], $currentSchemas);
56+
57+
return $index === false ? PHP_INT_MAX : $index;
58+
}
59+
)
60+
)->firstWhere('name', $tableName);
5161

5262
if (! $table) {
5363
$this->components->warn("Table [{$tableName}] doesn't exist.");

0 commit comments

Comments
 (0)