Skip to content

Commit bee4fd6

Browse files
[10.x] Clean up DBAL deprecations (#45289)
* Clean up DBAL deprecations * wip * wip * wip * Apply fixes from StyleCI * Fix tests * revert * wip Co-authored-by: StyleCI Bot <[email protected]>
1 parent 1997729 commit bee4fd6

File tree

12 files changed

+37
-74
lines changed

12 files changed

+37
-74
lines changed

src/Illuminate/Database/Connection.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ public function useDefaultSchemaGrammar()
273273
/**
274274
* Get the default schema grammar instance.
275275
*
276-
* @return \Illuminate\Database\Schema\Grammars\Grammar
276+
* @return \Illuminate\Database\Schema\Grammars\Grammar|null
277277
*/
278278
protected function getDefaultSchemaGrammar()
279279
{
@@ -1097,7 +1097,7 @@ public function getDoctrineColumn($table, $column)
10971097
{
10981098
$schema = $this->getDoctrineSchemaManager();
10991099

1100-
return $schema->listTableDetails($table)->getColumn($column);
1100+
return $schema->introspectTable($table)->getColumn($column);
11011101
}
11021102

11031103
/**
@@ -1109,11 +1109,7 @@ public function getDoctrineSchemaManager()
11091109
{
11101110
$connection = $this->getDoctrineConnection();
11111111

1112-
// Doctrine v2 expects one parameter while v3 expects two. 2nd will be ignored on v2...
1113-
return $this->getDoctrineDriver()->getSchemaManager(
1114-
$connection,
1115-
$connection->getDatabasePlatform()
1116-
);
1112+
return $connection->createSchemaManager();
11171113
}
11181114

11191115
/**
@@ -1151,7 +1147,7 @@ public function getDoctrineConnection()
11511147
* @param string $type
11521148
* @return void
11531149
*
1154-
* @throws \Doctrine\DBAL\DBALException
1150+
* @throws \Doctrine\DBAL\Exception
11551151
* @throws \RuntimeException
11561152
*/
11571153
public function registerDoctrineType(Type|string $class, string $name, string $type): void

src/Illuminate/Database/Connectors/Connector.php

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace Illuminate\Database\Connectors;
44

5-
use Doctrine\DBAL\Driver\PDOConnection;
65
use Exception;
76
use Illuminate\Database\DetectsLostConnections;
87
use PDO;
@@ -63,25 +62,9 @@ public function createConnection($dsn, array $config, array $options)
6362
*/
6463
protected function createPdoConnection($dsn, $username, $password, $options)
6564
{
66-
if (class_exists(PDOConnection::class) && ! $this->isPersistentConnection($options)) {
67-
return new PDOConnection($dsn, $username, $password, $options);
68-
}
69-
7065
return new PDO($dsn, $username, $password, $options);
7166
}
7267

73-
/**
74-
* Determine if the connection is persistent.
75-
*
76-
* @param array $options
77-
* @return bool
78-
*/
79-
protected function isPersistentConnection($options)
80-
{
81-
return isset($options[PDO::ATTR_PERSISTENT]) &&
82-
$options[PDO::ATTR_PERSISTENT];
83-
}
84-
8568
/**
8669
* Handle an exception that occurred during connect execution.
8770
*

src/Illuminate/Database/Console/ShowCommand.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,15 @@ public function handle(ConnectionResolverInterface $connections)
4444

4545
$connection = $connections->connection($database = $this->input->getOption('database'));
4646

47+
$doctrineConnection = $connection->getDoctrineConnection();
4748
$schema = $connection->getDoctrineSchemaManager();
4849

49-
$this->registerTypeMappings($schema->getDatabasePlatform());
50+
$this->registerTypeMappings($doctrineConnection->getDatabasePlatform());
5051

5152
$data = [
5253
'platform' => [
5354
'config' => $this->getConfigFromDatabase($database),
54-
'name' => $this->getPlatformName($schema->getDatabasePlatform(), $database),
55+
'name' => $this->getPlatformName($doctrineConnection->getDatabasePlatform(), $database),
5556
'open_connections' => $this->getConnectionCount($connection),
5657
],
5758
'tables' => $this->tables($connection, $schema),

src/Illuminate/Database/Console/ShowModelCommand.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class ShowModelCommand extends DatabaseInspectionCommand
7676
/**
7777
* Execute the console command.
7878
*
79-
* @return void
79+
* @return int
8080
*/
8181
public function handle()
8282
{
@@ -113,7 +113,7 @@ public function handle()
113113
* Get the first policy associated with this model.
114114
*
115115
* @param \Illuminate\Database\Eloquent\Model $model
116-
* @return Illuminate\Support\Collection
116+
* @return string
117117
*/
118118
protected function getPolicy($model)
119119
{
@@ -131,8 +131,9 @@ protected function getPolicy($model)
131131
*/
132132
protected function getAttributes($model)
133133
{
134-
$schema = $model->getConnection()->getDoctrineSchemaManager();
135-
$this->registerTypeMappings($schema->getDatabasePlatform());
134+
$connection = $model->getConnection();
135+
$schema = $connection->getDoctrineSchemaManager();
136+
$this->registerTypeMappings($connection->getDoctrineConnection()->getDatabasePlatform());
136137
$table = $model->getConnection()->getTablePrefix().$model->getTable();
137138
$columns = $schema->listTableColumns($table);
138139
$indexes = $schema->listTableIndexes($table);
@@ -244,7 +245,7 @@ protected function getRelations($model)
244245
* Get the Observers watching this model.
245246
*
246247
* @param \Illuminate\Database\Eloquent\Model $model
247-
* @return Illuminate\Support\Collection
248+
* @return \Illuminate\Support\Collection
248249
*/
249250
protected function getObservers($model)
250251
{

src/Illuminate/Database/Console/TableCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function handle(ConnectionResolverInterface $connections)
4545

4646
$schema = $connection->getDoctrineSchemaManager();
4747

48-
$this->registerTypeMappings($schema->getDatabasePlatform());
48+
$this->registerTypeMappings($connection->getDoctrineConnection()->getDatabasePlatform());
4949

5050
$table = $this->argument('table') ?: $this->components->choice(
5151
'Which table would you like to inspect?',
@@ -56,7 +56,7 @@ public function handle(ConnectionResolverInterface $connections)
5656
return $this->components->warn("Table [{$table}] doesn't exist.");
5757
}
5858

59-
$table = $schema->listTableDetails($table);
59+
$table = $schema->introspectTable($table);
6060

6161
$columns = $this->columns($table);
6262
$indexes = $this->indexes($table);

src/Illuminate/Database/DatabaseManager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ protected function registerConfiguredDoctrineTypes(Connection $connection): void
245245
* @param string $type
246246
* @return void
247247
*
248-
* @throws \Doctrine\DBAL\DBALException
248+
* @throws \Doctrine\DBAL\Exception
249249
* @throws \RuntimeException
250250
*/
251251
public function registerDoctrineType(string $class, string $name, string $type): void

src/Illuminate/Database/Migrations/Migrator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,7 @@ public function hasRunAnyMigrations()
703703
*/
704704
public function deleteRepository()
705705
{
706-
return $this->repository->deleteRepository();
706+
$this->repository->deleteRepository();
707707
}
708708

709709
/**

src/Illuminate/Database/Schema/Grammars/ChangeColumn.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@ public static function compile($grammar, Blueprint $blueprint, Fluent $command,
3434
}
3535

3636
$schema = $connection->getDoctrineSchemaManager();
37-
$databasePlatform = $schema->getDatabasePlatform();
37+
$databasePlatform = $connection->getDoctrineConnection()->getDatabasePlatform();
3838
$databasePlatform->registerDoctrineTypeMapping('enum', 'string');
3939

4040
$tableDiff = static::getChangedDiff(
4141
$grammar, $blueprint, $schema
4242
);
4343

44-
if ($tableDiff !== false) {
44+
if (! $tableDiff->isEmpty()) {
4545
return (array) $databasePlatform->getAlterTableSQL($tableDiff);
4646
}
4747

@@ -54,13 +54,13 @@ public static function compile($grammar, Blueprint $blueprint, Fluent $command,
5454
* @param \Illuminate\Database\Schema\Grammars\Grammar $grammar
5555
* @param \Illuminate\Database\Schema\Blueprint $blueprint
5656
* @param \Doctrine\DBAL\Schema\AbstractSchemaManager $schema
57-
* @return \Doctrine\DBAL\Schema\TableDiff|bool
57+
* @return \Doctrine\DBAL\Schema\TableDiff
5858
*/
5959
protected static function getChangedDiff($grammar, Blueprint $blueprint, SchemaManager $schema)
6060
{
61-
$current = $schema->listTableDetails($grammar->getTablePrefix().$blueprint->getTable());
61+
$current = $schema->introspectTable($grammar->getTablePrefix().$blueprint->getTable());
6262

63-
return (new Comparator)->diffTable(
63+
return (new Comparator)->compareTables(
6464
$current, static::getTableWithColumnChanges($blueprint, $current)
6565
);
6666
}
@@ -89,7 +89,7 @@ protected static function getTableWithColumnChanges(Blueprint $blueprint, Table
8989
continue;
9090
}
9191

92-
$column->setCustomSchemaOption($option, static::mapFluentValueToDoctrine($option, $value));
92+
$column->setPlatformOption($option, static::mapFluentValueToDoctrine($option, $value));
9393
}
9494
}
9595
}
@@ -106,7 +106,7 @@ protected static function getTableWithColumnChanges(Blueprint $blueprint, Table
106106
*/
107107
protected static function getDoctrineColumn(Table $table, Fluent $fluent)
108108
{
109-
return $table->changeColumn(
109+
return $table->modifyColumn(
110110
$fluent['name'], static::getDoctrineColumnChangeOptions($fluent)
111111
)->getColumn($fluent['name']);
112112
}

src/Illuminate/Database/Schema/Grammars/Grammar.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ abstract class Grammar extends BaseGrammar
1717
{
1818
use CompilesJsonPaths;
1919

20+
/**
21+
* The possible column modifiers.
22+
*
23+
* @var string[]
24+
*/
25+
protected $modifiers = [];
26+
2027
/**
2128
* If this Grammar supports schema changes wrapped in a transaction.
2229
*
@@ -319,7 +326,7 @@ public function getDoctrineTableDiff(Blueprint $blueprint, SchemaManager $schema
319326
$table = $this->getTablePrefix().$blueprint->getTable();
320327

321328
return tap(new TableDiff($table), function ($tableDiff) use ($schema, $table) {
322-
$tableDiff->fromTable = $schema->listTableDetails($table);
329+
$tableDiff->fromTable = $schema->introspectTable($table);
323330
});
324331
}
325332

src/Illuminate/Database/Schema/Grammars/RenameColumn.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class RenameColumn
2323
public static function compile(Grammar $grammar, Blueprint $blueprint, Fluent $command, Connection $connection)
2424
{
2525
$schema = $connection->getDoctrineSchemaManager();
26-
$databasePlatform = $schema->getDatabasePlatform();
26+
$databasePlatform = $connection->getDoctrineConnection()->getDatabasePlatform();
2727
$databasePlatform->registerDoctrineTypeMapping('enum', 'string');
2828

2929
$column = $connection->getDoctrineColumn(

0 commit comments

Comments
 (0)