Skip to content

Commit

Permalink
Merge pull request #3197 from vlad-ghita/mysql-json-detection
Browse files Browse the repository at this point in the history
Detect JSON for non-specialized MySQL platform instances.
  • Loading branch information
bobdenotter authored May 23, 2022
2 parents e71625f + 594f559 commit c344c82
Showing 1 changed file with 26 additions and 0 deletions.
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

0 comments on commit c344c82

Please sign in to comment.