Skip to content

Commit

Permalink
[11.x] Support for Doctrine DBAL 4 (#48752)
Browse files Browse the repository at this point in the history
* Doctrine 4

Signed-off-by: Mior Muhammad Zaki <[email protected]>

* Apply fixes from StyleCI

* wip

* wip

Signed-off-by: Mior Muhammad Zaki <[email protected]>

* wip

Signed-off-by: Mior Muhammad Zaki <[email protected]>

* wip

Signed-off-by: Mior Muhammad Zaki <[email protected]>

* wip

Signed-off-by: Mior Muhammad Zaki <[email protected]>

* wip

Signed-off-by: Mior Muhammad Zaki <[email protected]>

* wip

Signed-off-by: Mior Muhammad Zaki <[email protected]>

* wip

Signed-off-by: Mior Muhammad Zaki <[email protected]>

* wip

Signed-off-by: Mior Muhammad Zaki <[email protected]>

* wip

Signed-off-by: Mior Muhammad Zaki <[email protected]>

* wip

Signed-off-by: Mior Muhammad Zaki <[email protected]>

* wip

Signed-off-by: Mior Muhammad Zaki <[email protected]>

* wip

Signed-off-by: Mior Muhammad Zaki <[email protected]>

* wip

Signed-off-by: Mior Muhammad Zaki <[email protected]>

* Apply fixes from StyleCI

* wip

Signed-off-by: Mior Muhammad Zaki <[email protected]>

* wip

Signed-off-by: Mior Muhammad Zaki <[email protected]>

* wip

Signed-off-by: Mior Muhammad Zaki <[email protected]>

* wip

Signed-off-by: Mior Muhammad Zaki <[email protected]>

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

* wip

Signed-off-by: Mior Muhammad Zaki <[email protected]>

---------

Signed-off-by: Mior Muhammad Zaki <[email protected]>
Co-authored-by: StyleCI Bot <[email protected]>
Co-authored-by: Dries Vints <[email protected]>
  • Loading branch information
3 people authored Oct 24, 2023
1 parent 7132603 commit d9d549d
Show file tree
Hide file tree
Showing 22 changed files with 271 additions and 231 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
"ext-gmp": "*",
"ably/ably-php": "^1.0",
"aws/aws-sdk-php": "^3.235.5",
"doctrine/dbal": "^3.5.1",
"doctrine/dbal": "^4.0",
"fakerphp/faker": "^1.21",
"guzzlehttp/guzzle": "^7.6",
"league/flysystem-aws-s3-v3": "^3.0",
Expand Down Expand Up @@ -161,7 +161,7 @@
"ably/ably-php": "Required to use the Ably broadcast driver (^1.0).",
"aws/aws-sdk-php": "Required to use the SQS queue driver, DynamoDb failed job storage, and SES mail driver (^3.235.5).",
"brianium/paratest": "Required to run tests in parallel (^6.0).",
"doctrine/dbal": "Required to rename columns and drop SQLite columns (^3.5.1).",
"doctrine/dbal": "Required to rename columns and drop SQLite columns (^4.0).",
"fakerphp/faker": "Required to use the eloquent factory builder (^1.9.1).",
"filp/whoops": "Required for friendly error pages in development (^2.14.3).",
"guzzlehttp/guzzle": "Required to use the HTTP Client and the ping methods on schedules (^7.6).",
Expand Down
28 changes: 9 additions & 19 deletions src/Illuminate/Database/DBAL/TimestampType.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,14 @@

namespace Illuminate\Database\DBAL;

use Doctrine\DBAL\Exception as DBALException;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Platforms\MariaDb1027Platform;
use Doctrine\DBAL\Platforms\MariaDb1052Platform;
use Doctrine\DBAL\Platforms\Exception\NotSupported;
use Doctrine\DBAL\Platforms\MariaDB1052Platform;
use Doctrine\DBAL\Platforms\MariaDBPlatform;
use Doctrine\DBAL\Platforms\MySQL57Platform;
use Doctrine\DBAL\Platforms\MySQL80Platform;
use Doctrine\DBAL\Platforms\MySQLPlatform;
use Doctrine\DBAL\Platforms\PostgreSQL100Platform;
use Doctrine\DBAL\Platforms\PostgreSQL94Platform;
use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
use Doctrine\DBAL\Platforms\SqlitePlatform;
use Doctrine\DBAL\Platforms\SQLServer2012Platform;
use Doctrine\DBAL\Platforms\SQLitePlatform;
use Doctrine\DBAL\Platforms\SQLServerPlatform;
use Doctrine\DBAL\Types\PhpDateTimeMappingType;
use Doctrine\DBAL\Types\Type;
Expand All @@ -24,24 +19,19 @@ class TimestampType extends Type implements PhpDateTimeMappingType
/**
* {@inheritdoc}
*
* @throws DBALException
* @throws \Doctrine\DBAL\Platforms\Exception\NotSupported
*/
public function getSQLDeclaration(array $column, AbstractPlatform $platform): string
{
return match (get_class($platform)) {
MySQLPlatform::class,
MySQL57Platform::class,
MySQL80Platform::class,
MariaDBPlatform::class,
MariaDb1027Platform::class,
MariaDb1052Platform::class, => $this->getMySqlPlatformSQLDeclaration($column),
PostgreSQLPlatform::class,
PostgreSQL94Platform::class,
PostgreSQL100Platform::class => $this->getPostgresPlatformSQLDeclaration($column),
SQLServerPlatform::class,
SQLServer2012Platform::class => $this->getSqlServerPlatformSQLDeclaration($column),
SqlitePlatform::class => 'DATETIME',
default => throw new DBALException('Invalid platform: '.substr(strrchr(get_class($platform), '\\'), 1)),
MariaDB1052Platform::class, => $this->getMySqlPlatformSQLDeclaration($column),
PostgreSQLPlatform::class => $this->getPostgresPlatformSQLDeclaration($column),
SQLServerPlatform::class => $this->getSqlServerPlatformSQLDeclaration($column),
SQLitePlatform::class => 'DATETIME',
default => throw NotSupported::new('TIMESTAMP'),
};
}

Expand Down
6 changes: 2 additions & 4 deletions src/Illuminate/Database/PDO/Concerns/ConnectsToDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Illuminate\Database\PDO\Concerns;

use Doctrine\DBAL\Driver\Connection as ConnectionContract;
use Illuminate\Database\PDO\Connection;
use InvalidArgumentException;
use PDO;
Expand All @@ -12,14 +13,11 @@ trait ConnectsToDatabase
* Create a new database connection.
*
* @param mixed[] $params
* @param string|null $username
* @param string|null $password
* @param mixed[] $driverOptions
* @return \Illuminate\Database\PDO\Connection
*
* @throws \InvalidArgumentException
*/
public function connect(array $params, $username = null, $password = null, array $driverOptions = [])
public function connect(array $params): ConnectionContract
{
if (! isset($params['pdo']) || ! $params['pdo'] instanceof PDO) {
throw new InvalidArgumentException('Laravel requires the "pdo" property to be set and be a PDO instance.');
Expand Down
34 changes: 17 additions & 17 deletions src/Illuminate/Database/PDO/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@

namespace Illuminate\Database\PDO;

use Doctrine\DBAL\Driver\Connection as ConnectionContract;
use Doctrine\DBAL\Driver\PDO\Exception;
use Doctrine\DBAL\Driver\PDO\Result;
use Doctrine\DBAL\Driver\PDO\Statement;
use Doctrine\DBAL\Driver\Result as ResultInterface;
use Doctrine\DBAL\Driver\ServerInfoAwareConnection;
use Doctrine\DBAL\Driver\Statement as StatementInterface;
use Doctrine\DBAL\ParameterType;
use PDO;
use PDOException;
use PDOStatement;

class Connection implements ServerInfoAwareConnection
class Connection implements ConnectionContract
{
/**
* The underlying PDO connection.
Expand Down Expand Up @@ -94,11 +94,11 @@ public function query(string $sql): ResultInterface
* Get the last insert ID.
*
* @param string|null $name
* @return mixed
* @return string|int
*
* @throws \Doctrine\DBAL\Driver\PDO\Exception
*/
public function lastInsertId($name = null)
public function lastInsertId($name = null): string|int
{
try {
if ($name === null) {
Expand All @@ -125,31 +125,31 @@ protected function createStatement(PDOStatement $stmt): Statement
/**
* Begin a new database transaction.
*
* @return bool
* @return void
*/
public function beginTransaction()
public function beginTransaction(): void
{
return $this->connection->beginTransaction();
$this->connection->beginTransaction();
}

/**
* Commit a database transaction.
*
* @return bool
* @return void
*/
public function commit()
public function commit(): void
{
return $this->connection->commit();
$this->connection->commit();
}

/**
* Rollback a database transaction.
*
* @return bool
* @return void
*/
public function rollBack()
public function rollBack(): void
{
return $this->connection->rollBack();
$this->connection->rollBack();
}

/**
Expand All @@ -159,7 +159,7 @@ public function rollBack()
* @param string $type
* @return string
*/
public function quote($input, $type = ParameterType::STRING)
public function quote($input, $type = ParameterType::STRING): string
{
return $this->connection->quote($input, $type);
}
Expand All @@ -169,17 +169,17 @@ public function quote($input, $type = ParameterType::STRING)
*
* @return string
*/
public function getServerVersion()
public function getServerVersion(): string
{
return $this->connection->getAttribute(PDO::ATTR_SERVER_VERSION);
}

/**
* Get the wrapped PDO connection.
* Get the native PDO connection.
*
* @return \PDO
*/
public function getWrappedConnection(): PDO
public function getNativeConnection(): PDO
{
return $this->connection;
}
Expand Down
34 changes: 17 additions & 17 deletions src/Illuminate/Database/PDO/SqlServerConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

namespace Illuminate\Database\PDO;

use Doctrine\DBAL\Driver\Connection as ConnectionContract;
use Doctrine\DBAL\Driver\PDO\SQLSrv\Statement;
use Doctrine\DBAL\Driver\Result;
use Doctrine\DBAL\Driver\ServerInfoAwareConnection;
use Doctrine\DBAL\Driver\Statement as StatementInterface;
use Doctrine\DBAL\ParameterType;
use PDO;

class SqlServerConnection implements ServerInfoAwareConnection
class SqlServerConnection implements ConnectionContract
{
/**
* The underlying connection instance.
Expand Down Expand Up @@ -68,9 +68,9 @@ public function exec(string $statement): int
* Get the last insert ID.
*
* @param string|null $name
* @return mixed
* @return string|int
*/
public function lastInsertId($name = null)
public function lastInsertId($name = null): string|int
{
if ($name === null) {
return $this->connection->lastInsertId($name);
Expand All @@ -84,31 +84,31 @@ public function lastInsertId($name = null)
/**
* Begin a new database transaction.
*
* @return bool
* @return void
*/
public function beginTransaction()
public function beginTransaction(): void
{
return $this->connection->beginTransaction();
$this->connection->beginTransaction();
}

/**
* Commit a database transaction.
*
* @return bool
* @return void
*/
public function commit()
public function commit(): void
{
return $this->connection->commit();
$this->connection->commit();
}

/**
* Rollback a database transaction.
*
* @return bool
* @return void
*/
public function rollBack()
public function rollBack(): void
{
return $this->connection->rollBack();
$this->connection->rollBack();
}

/**
Expand All @@ -118,7 +118,7 @@ public function rollBack()
* @param int $type
* @return string
*/
public function quote($value, $type = ParameterType::STRING)
public function quote($value, $type = ParameterType::STRING): string
{
$val = $this->connection->quote($value, $type);

Expand All @@ -135,17 +135,17 @@ public function quote($value, $type = ParameterType::STRING)
*
* @return string
*/
public function getServerVersion()
public function getServerVersion(): string
{
return $this->connection->getServerVersion();
}

/**
* Get the wrapped PDO connection.
* Get the native PDO connection.
*
* @return \PDO
*/
public function getWrappedConnection(): PDO
public function getNativeConnection(): PDO
{
return $this->connection->getWrappedConnection();
}
Expand Down
6 changes: 2 additions & 4 deletions src/Illuminate/Database/PDO/SqlServerDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,17 @@
namespace Illuminate\Database\PDO;

use Doctrine\DBAL\Driver\AbstractSQLServerDriver;
use Doctrine\DBAL\Driver\Connection as ConnectionContract;

class SqlServerDriver extends AbstractSQLServerDriver
{
/**
* Create a new database connection.
*
* @param mixed[] $params
* @param string|null $username
* @param string|null $password
* @param mixed[] $driverOptions
* @return \Illuminate\Database\PDO\SqlServerConnection
*/
public function connect(array $params, $username = null, $password = null, array $driverOptions = [])
public function connect(array $params): ConnectionContract
{
return new SqlServerConnection(
new Connection($params['pdo'])
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Database/Schema/Blueprint.php
Original file line number Diff line number Diff line change
Expand Up @@ -977,7 +977,7 @@ public function float($column, $total = 8, $places = 2, $unsigned = false)
* @param bool $unsigned
* @return \Illuminate\Database\Schema\ColumnDefinition
*/
public function double($column, $total = null, $places = null, $unsigned = false)
public function double($column, $total = 15, $places = 6, $unsigned = false)
{
return $this->addColumn('double', $column, compact('total', 'places', 'unsigned'));
}
Expand Down
4 changes: 3 additions & 1 deletion src/Illuminate/Database/Schema/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,9 @@ public function getColumnType($table, $column)
{
$table = $this->connection->getTablePrefix().$table;

return $this->connection->getDoctrineColumn($table, $column)->getType()->getName();
$type = $this->connection->getDoctrineColumn($table, $column)->getType();

return $type::lookupName($type);
}

/**
Expand Down
10 changes: 5 additions & 5 deletions src/Illuminate/Database/Schema/Grammars/ChangeColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,22 +118,22 @@ protected static function getDoctrineColumn(Table $table, Fluent $fluent)
*/
protected static function getDoctrineColumnChangeOptions(Fluent $fluent)
{
$options = ['type' => static::getDoctrineColumnType($fluent['type'])];
$options = ['Type' => static::getDoctrineColumnType($fluent['type'])];

if (! in_array($fluent['type'], ['smallint', 'integer', 'bigint'])) {
$options['autoincrement'] = false;
$options['Autoincrement'] = false;
}

if (in_array($fluent['type'], ['tinyText', 'text', 'mediumText', 'longText'])) {
$options['length'] = static::calculateDoctrineTextLength($fluent['type']);
$options['Length'] = static::calculateDoctrineTextLength($fluent['type']);
}

if ($fluent['type'] === 'char') {
$options['fixed'] = true;
$options['Fixed'] = true;
}

if (static::doesntNeedCharacterOptions($fluent['type'])) {
$options['customSchemaOptions'] = [
$options['PlatformOptions'] = [
'collation' => '',
'charset' => '',
];
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Database/Schema/Grammars/Grammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ public function getDoctrineTableDiff(Blueprint $blueprint, SchemaManager $schema

$table = $schema->introspectTable($tableName);

return new TableDiff(tableName: $tableName, fromTable: $table);
return $schema->createComparator()->compareTables(oldTable: $table, newTable: $table);
}

/**
Expand Down
Loading

0 comments on commit d9d549d

Please sign in to comment.