Skip to content

Detect JSON for non-specialized MySQL platform instances. #3197

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

Merged
merged 2 commits into from
May 23, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/Doctrine/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Doctrine\DBAL\Driver\PDOConnection;
use Doctrine\DBAL\Platforms\MariaDb1027Platform;
use Doctrine\DBAL\Platforms\MySQL57Platform;
use Doctrine\DBAL\Platforms\MySqlPlatform;
use Doctrine\DBAL\Platforms\PostgreSQL92Platform;
use Doctrine\DBAL\Platforms\SqlitePlatform;

Expand Down Expand Up @@ -97,6 +98,31 @@ public function hasJson(): bool
return true;
}

// Corner case where MySQL platform is not specialized.
// Was observed with deployment to platform.sh using oracle-mysql service.
if ($platform instanceof MySqlPlatform) {
// samples:
// 8.0.29
// 8.0.27-cluster
// 10.7.3-MariaDB-1:10.7.3+maria~focal
$serverVersion = $this->getPlatform()["server_version"];

if (!preg_match("/^\d+\.\d+\.\d+/", $serverVersion, $matches)) {
// should throw an error or something?
return false;
}

$actVersion = $matches[0];

$isMariaDb = is_int(mb_stripos($serverVersion, "maria"));
$minVersion = $isMariaDb
? "10.2.7" // taken from MariaDb1027Platform docs
: "5.7.9" // taken from MySQL57Platform docs
;

return version_compare($actVersion, $minVersion, ">=");
}

// PostgreSQL supports JSON from v9.2 and above, later versions are implicitly included
if ($platform instanceof PostgreSQL92Platform) {
return true;
Expand Down