Skip to content

Commit 3e8e907

Browse files
authored
Merge pull request #14 from dicoding-dev/feature/upgrade-doctrine-dbal
Upgrade `doctrine/dbal` from `2.x` to `3.x`
2 parents b444848 + bdeae41 commit 3e8e907

File tree

6 files changed

+35
-15
lines changed

6 files changed

+35
-15
lines changed

src/Illuminate/Database/Connection.php

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -822,7 +822,13 @@ public function getDoctrineColumn($table, $column)
822822
*/
823823
public function getDoctrineSchemaManager()
824824
{
825-
return $this->getDoctrineDriver()->getSchemaManager($this->getDoctrineConnection());
825+
$connection = $this->getDoctrineConnection();
826+
827+
// Doctrine v2 expects one parameter while v3 expects two. 2nd will be ignored on v2...
828+
return $this->getDoctrineDriver()->getSchemaManager(
829+
$connection,
830+
$connection->getDatabasePlatform()
831+
);
826832
}
827833

828834
/**
@@ -834,9 +840,14 @@ public function getDoctrineConnection()
834840
{
835841
$driver = $this->getDoctrineDriver();
836842

837-
$data = array('pdo' => $this->pdo, 'dbname' => $this->getConfig('database'));
838-
839-
return new DoctrineConnection($data, $driver);
843+
return new DoctrineConnection([
844+
'host' => $this->getConfig('host'),
845+
'port' => $this->getConfig('port'),
846+
'user' => $this->getConfig('username'),
847+
'password' => $this->getConfig('password'),
848+
'dbname' => $this->getDatabaseName(),
849+
'charset' => $this->getConfig('charset'),
850+
], $driver);
840851
}
841852

842853
/**

src/Illuminate/Database/MySqlConnection.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php namespace Illuminate\Database;
22

33
use Illuminate\Database\Schema\MySqlBuilder;
4-
use Doctrine\DBAL\Driver\PDOMySql\Driver as DoctrineDriver;
4+
use Doctrine\DBAL\Driver\PDO\MySQL\Driver as DoctrineDriver;
55
use Illuminate\Database\Query\Grammars\MySqlGrammar as QueryGrammar;
66
use Illuminate\Database\Schema\Grammars\MySqlGrammar as SchemaGrammar;
77

@@ -52,7 +52,7 @@ protected function getDefaultPostProcessor()
5252
/**
5353
* Get the Doctrine DBAL driver.
5454
*
55-
* @return \Doctrine\DBAL\Driver\PDOMySql\Driver
55+
* @return \Doctrine\DBAL\Driver\PDO\MySQL\Driver
5656
*/
5757
protected function getDoctrineDriver()
5858
{

src/Illuminate/Database/PostgresConnection.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php namespace Illuminate\Database;
22

3-
use Doctrine\DBAL\Driver\PDOPgSql\Driver as DoctrineDriver;
3+
use Doctrine\DBAL\Driver\PDO\PgSQL\Driver as DoctrineDriver;
44
use Illuminate\Database\Query\Processors\PostgresProcessor;
55
use Illuminate\Database\Query\Grammars\PostgresGrammar as QueryGrammar;
66
use Illuminate\Database\Schema\Grammars\PostgresGrammar as SchemaGrammar;
@@ -40,7 +40,7 @@ protected function getDefaultPostProcessor()
4040
/**
4141
* Get the Doctrine DBAL driver.
4242
*
43-
* @return \Doctrine\DBAL\Driver\PDOPgSql\Driver
43+
* @return \Doctrine\DBAL\Driver\PDO\PgSQL\Driver
4444
*/
4545
protected function getDoctrineDriver()
4646
{

src/Illuminate/Database/SQLiteConnection.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php namespace Illuminate\Database;
22

3-
use Doctrine\DBAL\Driver\PDOSqlite\Driver as DoctrineDriver;
3+
use Doctrine\DBAL\Driver\PDO\SQLite\Driver as DoctrineDriver;
44
use Illuminate\Database\Query\Grammars\SQLiteGrammar as QueryGrammar;
55
use Illuminate\Database\Schema\Grammars\SQLiteGrammar as SchemaGrammar;
66

@@ -39,7 +39,7 @@ protected function getDefaultPostProcessor()
3939
/**
4040
* Get the Doctrine DBAL driver.
4141
*
42-
* @return \Doctrine\DBAL\Driver\PDOSqlite\Driver
42+
* @return \Doctrine\DBAL\Driver\PDO\SQLite\Driver
4343
*/
4444
protected function getDoctrineDriver()
4545
{

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,22 @@ protected function getRenamedDiff(Blueprint $blueprint, Fluent $command, Column
6363
*/
6464
protected function setRenamedColumns(TableDiff $tableDiff, Fluent $command, Column $column)
6565
{
66-
$newColumn = new Column($command->to, $column->getType(), $column->toArray());
67-
68-
$tableDiff->renamedColumns = array($command->from => $newColumn);
66+
$tableDiff->renamedColumns = array(
67+
$command->from => new Column($command->to, $column->getType(), self::getWritableColumnOptions($column))
68+
);
6969

7070
return $tableDiff;
7171
}
7272

73+
private static function getWritableColumnOptions(Column $column): array
74+
{
75+
return array_filter(
76+
$column->toArray(),
77+
fn (string $name) => method_exists($column, 'set'.$name),
78+
ARRAY_FILTER_USE_KEY
79+
);
80+
}
81+
7382
/**
7483
* Compile a foreign key command.
7584
*

src/Illuminate/Database/SqlServerConnection.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php namespace Illuminate\Database;
22

33
use Closure;
4-
use Doctrine\DBAL\Driver\PDOSqlsrv\Driver as DoctrineDriver;
4+
use Doctrine\DBAL\Driver\PDO\SQLSrv\Driver as DoctrineDriver;
55
use Illuminate\Database\Query\Processors\SqlServerProcessor;
66
use Illuminate\Database\Query\Grammars\SqlServerGrammar as QueryGrammar;
77
use Illuminate\Database\Schema\Grammars\SqlServerGrammar as SchemaGrammar;
@@ -87,7 +87,7 @@ protected function getDefaultPostProcessor()
8787
/**
8888
* Get the Doctrine DBAL Driver.
8989
*
90-
* @return \Doctrine\DBAL\Driver\PDOSqlsrv\Driver
90+
* @return \Doctrine\DBAL\Driver\PDO\SQLSrv\Driver
9191
*/
9292
protected function getDoctrineDriver()
9393
{

0 commit comments

Comments
 (0)