Skip to content

Commit 8de4eb9

Browse files
committed
Pass down the serverVersion database connection option to Doctrine DBAL connection
I got into this issue when I was trying to run the migrations against Azure's MySQL database. Azure's setup uses a gateway [1] to proxy connections to the correct server, which tricks PDO, because the gateway version is different than the actual server that the migration runs is 5.7, while the gateway server runs a 5.6. By using this option, we can manually pass the server version (5.7) and the correct data types will be mapped. In my case, JSON columns were throwing exception, even though they are supported in the actual server [2]. References: [1](https://docs.microsoft.com/en-us/azure/mysql/concepts-supported-versions) [2](https://www.doctrine-project.org/projects/doctrine-dbal/en/2.9/reference/configuration.html#automatic-platform-version-detection)
1 parent 7b2ba16 commit 8de4eb9

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

src/Illuminate/Database/Connection.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -897,11 +897,15 @@ public function getDoctrineConnection()
897897
if (is_null($this->doctrineConnection)) {
898898
$driver = $this->getDoctrineDriver();
899899

900-
$this->doctrineConnection = new DoctrineConnection([
900+
$this->doctrineConnection = new DoctrineConnection(array_filter([
901901
'pdo' => $this->getPdo(),
902902
'dbname' => $this->getConfig('database'),
903903
'driver' => $driver->getName(),
904-
], $driver);
904+
// One can manually pass the serverVersion config to the database connection
905+
// options. This is used by Doctrine instead of going through the regular
906+
// regular platform version detection. This config was not being used.
907+
'serverVersion' => $this->getConfig('serverVersion'),
908+
]), $driver);
905909
}
906910

907911
return $this->doctrineConnection;

0 commit comments

Comments
 (0)