-
-
Notifications
You must be signed in to change notification settings - Fork 454
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DBAL 4 compatibility #1707
DBAL 4 compatibility #1707
Conversation
e33d951
to
8ca42b4
Compare
@@ -102,7 +108,11 @@ public function createConnection(array $params, ?Configuration $config = null, ? | |||
$connection = DriverManager::getConnection($params, $config, $eventManager); | |||
$params = $this->addDatabaseSuffix(array_merge($connection->getParams(), $overriddenOptions)); | |||
$driver = $connection->getDriver(); | |||
$platform = $driver->getDatabasePlatform(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so previously this skipped any server version and for mysql for example just returned MySQLPlatform
.
We could use $connection->getDatabasePlatform()
but it would mean we auto-detect the server version which could mean we actually connect to the database. We should avoid that here I guess.
Is there any other way to do this with DBAL 4 except for using a StaticServerVersionProvider
with a fallback to an empty server version? 🙈 🤔
@derrabus maybe you have an idea
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so previously this skipped any server version and for mysql for example just returned
MySQLPlatform
.
Why though? For MySQL drivers especially, this sounds like a bad idea because we need the server version to determine whether we talk to a MySQL or a MariaDB.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We check if its a "Mysql like" platform (AbstractMySQLPlatform
) to set the collation
option 🤔
See
DoctrineBundle/ConnectionFactory.php
Lines 105 to 127 in b1ff934
$platform = $driver->getDatabasePlatform(); | |
if (! isset($params['charset'])) { | |
if ($platform instanceof AbstractMySQLPlatform) { | |
$params['charset'] = 'utf8mb4'; | |
if (isset($params['defaultTableOptions']['collate'])) { | |
Deprecation::trigger( | |
'doctrine/doctrine-bundle', | |
'https://github.com/doctrine/dbal/issues/5214', | |
'The "collate" default table option is deprecated in favor of "collation" and will be removed in doctrine/doctrine-bundle 3.0. ' | |
); | |
$params['defaultTableOptions']['collation'] = $params['defaultTableOptions']['collate']; | |
unset($params['defaultTableOptions']['collate']); | |
} | |
if (! isset($params['defaultTableOptions']['collation'])) { | |
$params['defaultTableOptions']['collation'] = 'utf8mb4_unicode_ci'; | |
} | |
} else { | |
$params['charset'] = 'utf8'; | |
} | |
} |
Maybe this isn't even needed anymore on DBAL 4? See doctrine/dbal#5214, doctrine/dbal#5246
I believe AbstractMySQLPlatform
only handles collation
on 4.0, or?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm but we also set a default charset utf8mb4
for those platforms 🤔 We have to keep this I think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not using $connection->getDatabasePlatform()
instead, which would automatically use the version provider based on the configuration ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or better, using $this->getDatabasePlatform()
to have the better error message telling you how to do if you want to be able to instantiate the connection in environments not able to connect yet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried this but it would mean we might connect to the database to determine the platform version (if not specified via config). For example all over the testsuite we would try to connect to some mysql db.
Since this is the initial connection that is replaced further down with changed parameters: we should avoid connecting, or?
@@ -102,7 +108,11 @@ public function createConnection(array $params, ?Configuration $config = null, ? | |||
$connection = DriverManager::getConnection($params, $config, $eventManager); | |||
$params = $this->addDatabaseSuffix(array_merge($connection->getParams(), $overriddenOptions)); | |||
$driver = $connection->getDriver(); | |||
$platform = $driver->getDatabasePlatform(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not using $connection->getDatabasePlatform()
instead, which would automatically use the version provider based on the configuration ?
@@ -102,7 +108,11 @@ public function createConnection(array $params, ?Configuration $config = null, ? | |||
$connection = DriverManager::getConnection($params, $config, $eventManager); | |||
$params = $this->addDatabaseSuffix(array_merge($connection->getParams(), $overriddenOptions)); | |||
$driver = $connection->getDriver(); | |||
$platform = $driver->getDatabasePlatform(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or better, using $this->getDatabasePlatform()
to have the better error message telling you how to do if you want to be able to instantiate the connection in environments not able to connect yet.
@derrabus this one needs rebasing to fix conflicts. Also, I'd like to release 2.11.0 to have the other new features available. Should I wait for this PR or delay it to 2.12 ? |
@stof I'd like to see if we can get ORM 3 support done for 2.11 as well. Can you hold back the release for one more day? |
yes |
This adds compatibility with DBAL 4 (ignoring ORM 3 for now).