Skip to content

Commit

Permalink
[11.x] Remove Doctrine DBAL (#48864)
Browse files Browse the repository at this point in the history
* remove doctrine dbal from grammar

* remove unused imports

* fix tests

* fix tests

* remove mysql 5.7 tests

* fix facade doctype

* use native column modifying by default

* fix tests

* fix tests

* wip

* Revert "remove mysql 5.7 tests"

This reverts commit ba31106.

* support native column renaming on MySQL 5.7

* fix style

* wip

* wip

* remove doctrine usage on DatabaseTruncation

* wip

* rename index on sqlite

* remove doctrine/dbal from db commands

* fix styles

* wip

* wip

* support renaming columns on legacy MariaDB

* remove redundant non-standard tests

* add collation modifier to sqlite

* support native column modifying on sqlite

* fix styles

* add user-defined types to db:show

* wip

* fix styles

* fix dropForeign exception on SQLite

* fix styles

* include generated and hidden columns on sqlite

* remove custom doctrine types

* remove doctrine change column

* styling

* remove support for registering custom doctrine types

* remove unused config methods and property

* remove redundant semicolon

* force re-run tests

* remove doctrine related conflicts

reverts #49438 and #49456

* remove doctrine/dbal from require-dev

* Revert "remove doctrine/dbal from require-dev"

This reverts commit fc4dd91.

* revert unrelated changes

* disable foreign key constraints when altering table on SQLite

* fix styling

* consider backticks when parsing collate on SQLite

* update facade docblocks

* remove doctrine connection

* formatting

* fix conflicts

* formatting

---------

Co-authored-by: Taylor Otwell <[email protected]>
  • Loading branch information
hafezdivandari and taylorotwell authored Jan 9, 2024
1 parent 0ca166c commit 9ccf003
Show file tree
Hide file tree
Showing 46 changed files with 651 additions and 2,101 deletions.
4 changes: 0 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@
"ext-gmp": "*",
"ably/ably-php": "^1.0",
"aws/aws-sdk-php": "^3.235.5",
"doctrine/dbal": "^4.0",
"fakerphp/faker": "^1.23",
"guzzlehttp/guzzle": "^7.8",
"league/flysystem-aws-s3-v3": "^3.0",
Expand All @@ -120,8 +119,6 @@
"psr/simple-cache-implementation": "1.0|2.0|3.0"
},
"conflict": {
"carbonphp/carbon-doctrine-types": "<3.0.0|>=4.0",
"doctrine/dbal": "<4.0.0|>=5.0",
"tightenco/collect": "<5.5.33"
},
"autoload": {
Expand Down Expand Up @@ -167,7 +164,6 @@
"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 (^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.8).",
Expand Down
130 changes: 10 additions & 120 deletions src/Illuminate/Database/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
use Carbon\CarbonInterval;
use Closure;
use DateTimeInterface;
use Doctrine\DBAL\Connection as DoctrineConnection;
use Doctrine\DBAL\Types\Type;
use Exception;
use Illuminate\Contracts\Events\Dispatcher;
use Illuminate\Database\Events\QueryExecuted;
Expand Down Expand Up @@ -189,20 +187,6 @@ class Connection implements ConnectionInterface
*/
protected $beforeExecutingCallbacks = [];

/**
* The instance of Doctrine connection.
*
* @var \Doctrine\DBAL\Connection
*/
protected $doctrineConnection;

/**
* Type mappings that should be registered with new Doctrine connections.
*
* @var array<string, string>
*/
protected $doctrineTypeMappings = [];

/**
* The connection resolvers.
*
Expand Down Expand Up @@ -989,8 +973,6 @@ protected function tryAgainIfCausedByLostConnection(QueryException $e, $query, $
public function reconnect()
{
if (is_callable($this->reconnector)) {
$this->doctrineConnection = null;

return call_user_func($this->reconnector, $this);
}

Expand All @@ -1017,8 +999,6 @@ public function reconnectIfMissingConnection()
public function disconnect()
{
$this->setPdo(null)->setReadPdo(null);

$this->doctrineConnection = null;
}

/**
Expand Down Expand Up @@ -1208,106 +1188,6 @@ public function useWriteConnectionWhenReading($value = true)
return $this;
}

/**
* Is Doctrine available?
*
* @return bool
*/
public function isDoctrineAvailable()
{
return class_exists('Doctrine\DBAL\Connection');
}

/**
* Indicates whether native alter operations will be used when dropping, renaming, or modifying columns, even if Doctrine DBAL is installed.
*
* @return bool
*/
public function usingNativeSchemaOperations()
{
return ! $this->isDoctrineAvailable() || SchemaBuilder::$alwaysUsesNativeSchemaOperationsIfPossible;
}

/**
* Get a Doctrine Schema Column instance.
*
* @param string $table
* @param string $column
* @return \Doctrine\DBAL\Schema\Column
*/
public function getDoctrineColumn($table, $column)
{
$schema = $this->getDoctrineSchemaManager();

return $schema->introspectTable($table)->getColumn($column);
}

/**
* Get the Doctrine DBAL schema manager for the connection.
*
* @return \Doctrine\DBAL\Schema\AbstractSchemaManager
*/
public function getDoctrineSchemaManager()
{
$connection = $this->getDoctrineConnection();

return $connection->createSchemaManager();
}

/**
* Get the Doctrine DBAL database connection instance.
*
* @return \Doctrine\DBAL\Connection
*/
public function getDoctrineConnection()
{
if (is_null($this->doctrineConnection)) {
$driver = $this->getDoctrineDriver();

$this->doctrineConnection = new DoctrineConnection(array_filter([
'pdo' => $this->getPdo(),
'dbname' => $this->getDatabaseName(),
'driver' => $driver->getName(),
'serverVersion' => $this->getConfig('server_version'),
]), $driver);

foreach ($this->doctrineTypeMappings as $name => $type) {
$this->doctrineConnection
->getDatabasePlatform()
->registerDoctrineTypeMapping($type, $name);
}
}

return $this->doctrineConnection;
}

/**
* Register a custom Doctrine mapping type.
*
* @param Type|class-string<Type> $class
* @param string $name
* @param string $type
* @return void
*
* @throws \Doctrine\DBAL\Exception
* @throws \RuntimeException
*/
public function registerDoctrineType(Type|string $class, string $name, string $type): void
{
if (! $this->isDoctrineAvailable()) {
throw new RuntimeException(
'Registering a custom Doctrine type requires Doctrine DBAL (doctrine/dbal).'
);
}

if (! Type::hasType($name)) {
Type::getTypeRegistry()
->register($name, is_string($class) ? new $class() : $class);
}

$this->doctrineTypeMappings[$name] = $type;
}

/**
* Get the current PDO connection.
*
Expand Down Expand Up @@ -1722,6 +1602,16 @@ public function withTablePrefix(Grammar $grammar)
return $grammar;
}

/**
* Get the server version for the connection.
*
* @return string
*/
public function getServerVersion(): string
{
return $this->getPdo()->getAttribute(PDO::ATTR_SERVER_VERSION);
}

/**
* Register a connection resolver.
*
Expand Down
Loading

0 comments on commit 9ccf003

Please sign in to comment.