Skip to content

Commit

Permalink
Merge pull request doctrine#5089 from morozov/remove-mysql-5.6
Browse files Browse the repository at this point in the history
Drop support for MySQL 5.6 and older and MariaDB 10.2.6 and older
  • Loading branch information
morozov committed Dec 12, 2021
2 parents befae82 + 8920d08 commit d8dc01f
Show file tree
Hide file tree
Showing 24 changed files with 257 additions and 674 deletions.
1 change: 0 additions & 1 deletion .github/workflows/continuous-integration.yml
Expand Up @@ -225,7 +225,6 @@ jobs:
php-version:
- "8.0"
mariadb-version:
- "10.0"
- "10.2"
- "10.5"
extension:
Expand Down
15 changes: 15 additions & 0 deletions UPGRADE.md
Expand Up @@ -12,6 +12,21 @@ awareness about deprecated code.

The `Doctrine\DBAL\Schema\Visitor\Graphviz` class has been removed.

## BC BREAK: Removed support for MariaDB 10.2.6 and older

MariaDB 10.2.6 and older are not supported anymore. The following classes have been removed:

* `Doctrine\DBAL\Platforms\MariaDb1027Platform`
* `Doctrine\DBAL\Platforms\Keywords\MariaDb102Keywords`

## BC BREAK: Removed support for MySQL 5.6 and older

MySQL 5.6 and older are not supported anymore. The following classes have been merged into their respective
parent classes:

* `Doctrine\DBAL\Platforms\MySQL57Platform`
* `Doctrine\DBAL\Platforms\Keywords\MySQL57Keywords`

## BC BREAK: Removed active support for Postgres 9

Postgres 9 is not actively supported anymore. The following classes have been merged into their respective parent class:
Expand Down
5 changes: 2 additions & 3 deletions docs/en/reference/platforms.rst
Expand Up @@ -33,14 +33,13 @@ can be found as follows:
MySQL
^^^^^

- ``MySQLPlatform`` for version 5.0 and above.
- ``MySQL57Platform`` for version 5.7 (5.7.9 GA) and above.
- ``MySQLPlatform`` for version 5.7 (5.7.9 GA) and above.
- ``MySQL80Platform`` for version 8.0 (8.0 GA) and above.

MariaDB
^^^^^

- ``MariaDb1027Platform`` for version 10.2 (10.2.7 GA) and above.
- ``MariaDBPlatform`` for version 10.2 (10.2.7 GA) and above.

Oracle
^^^^^^
Expand Down
11 changes: 0 additions & 11 deletions psalm.xml.dist
Expand Up @@ -39,17 +39,6 @@
<file name="src/Driver/OCI8/ConvertPositionalToNamedPlaceholders.php"/>
</errorLevel>
</ConflictingReferenceConstraint>
<DeprecatedClass>
<errorLevel type="suppress">
<!--
TODO: remove in 4.0.0
-->
<referencedClass name="Doctrine\DBAL\Platforms\Keywords\MariaDb102Keywords"/>
<referencedClass name="Doctrine\DBAL\Platforms\Keywords\MySQL57Keywords"/>
<referencedClass name="Doctrine\DBAL\Platforms\MariaDb1027Platform"/>
<referencedClass name="Doctrine\DBAL\Platforms\MySQL57Platform"/>
</errorLevel>
</DeprecatedClass>
<DeprecatedMethod>
<errorLevel type="suppress">
<!--
Expand Down
55 changes: 6 additions & 49 deletions src/Driver/AbstractMySQLDriver.php
Expand Up @@ -11,13 +11,11 @@
use Doctrine\DBAL\Platforms\AbstractMySQLPlatform;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Platforms\Exception\InvalidPlatformVersion;
use Doctrine\DBAL\Platforms\MariaDb1027Platform;
use Doctrine\DBAL\Platforms\MySQL57Platform;
use Doctrine\DBAL\Platforms\MariaDBPlatform;
use Doctrine\DBAL\Platforms\MySQL80Platform;
use Doctrine\DBAL\Platforms\MySQLPlatform;
use Doctrine\DBAL\Schema\MySQLSchemaManager;
use Doctrine\DBAL\ServerVersionProvider;
use Doctrine\Deprecations\Deprecation;

use function assert;
use function preg_match;
Expand All @@ -34,32 +32,17 @@ abstract class AbstractMySQLDriver implements Driver
*
* @throws Exception
*/
public function getDatabasePlatform(ServerVersionProvider $versionProvider): MySQLPlatform
public function getDatabasePlatform(ServerVersionProvider $versionProvider): AbstractMySQLPlatform
{
$version = $versionProvider->getServerVersion();
$mariadb = stripos($version, 'mariadb') !== false;
if ($mariadb && version_compare($this->getMariaDbMysqlVersionNumber($version), '10.2.7', '>=')) {
return new MariaDb1027Platform();
if (stripos($version, 'mariadb') !== false) {
return new MariaDBPlatform();
}

if (! $mariadb) {
$oracleMysqlVersion = $this->getOracleMysqlVersionNumber($version);
if (version_compare($oracleMysqlVersion, '8', '>=')) {
return new MySQL80Platform();
}

if (version_compare($oracleMysqlVersion, '5.7.9', '>=')) {
return new MySQL57Platform();
}
if (version_compare($this->getOracleMysqlVersionNumber($version), '8', '>=')) {
return new MySQL80Platform();
}

Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/5060',
'MySQL 5.6 support is deprecated and will be removed in DBAL 4.'
. ' Consider upgrading to MySQL 5.7 or later.'
);

return new MySQLPlatform();
}

Expand Down Expand Up @@ -97,32 +80,6 @@ private function getOracleMysqlVersionNumber(string $versionString): string
return $majorVersion . '.' . $minorVersion . '.' . $patchVersion;
}

/**
* Detect MariaDB server version, including hack for some mariadb distributions
* that starts with the prefix '5.5.5-'
*
* @param string $versionString Version string as returned by mariadb server, i.e. '5.5.5-Mariadb-10.0.8-xenial'
*
* @throws Exception
*/
private function getMariaDbMysqlVersionNumber(string $versionString): string
{
if (
preg_match(
'/^(?:5\.5\.5-)?(mariadb-)?(?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)/i',
$versionString,
$versionParts
) === 0
) {
throw InvalidPlatformVersion::new(
$versionString,
'^(?:5\.5\.5-)?(mariadb-)?<major_version>.<minor_version>.<patch_version>'
);
}

return $versionParts['major'] . '.' . $versionParts['minor'] . '.' . $versionParts['patch'];
}

public function getSchemaManager(Connection $conn, AbstractPlatform $platform): MySQLSchemaManager
{
assert($platform instanceof AbstractMySQLPlatform);
Expand Down
93 changes: 3 additions & 90 deletions src/Platforms/AbstractMySQLPlatform.php
Expand Up @@ -16,7 +16,6 @@
use Doctrine\DBAL\Types\BlobType;
use Doctrine\DBAL\Types\TextType;

use function array_diff_key;
use function array_merge;
use function array_unique;
use function array_values;
Expand Down Expand Up @@ -560,14 +559,12 @@ protected function getPreAlterTableIndexForeignKeySQL(TableDiff $diff): array
$diff->removedForeignKeys = [];
}

$sql = array_merge(
return array_merge(
$sql,
$this->getPreAlterTableAlterIndexForeignKeySQL($diff),
parent::getPreAlterTableIndexForeignKeySQL($diff),
$this->getPreAlterTableRenameIndexForeignKeySQL($diff)
);

return $sql;
}

/**
Expand Down Expand Up @@ -658,92 +655,7 @@ private function getPreAlterTableAlterIndexForeignKeySQL(TableDiff $diff): array
*/
protected function getPreAlterTableRenameIndexForeignKeySQL(TableDiff $diff): array
{
$sql = [];
$tableName = $diff->getName($this)->getQuotedName($this);

foreach ($this->getRemainingForeignKeyConstraintsRequiringRenamedIndexes($diff) as $foreignKey) {
if (in_array($foreignKey, $diff->changedForeignKeys, true)) {
continue;
}

$sql[] = $this->getDropForeignKeySQL($foreignKey->getQuotedName($this), $tableName);
}

return $sql;
}

/**
* Returns the remaining foreign key constraints that require one of the renamed indexes.
*
* "Remaining" here refers to the diff between the foreign keys currently defined in the associated
* table and the foreign keys to be removed.
*
* @param TableDiff $diff The table diff to evaluate.
*
* @return ForeignKeyConstraint[]
*/
private function getRemainingForeignKeyConstraintsRequiringRenamedIndexes(TableDiff $diff): array
{
if (empty($diff->renamedIndexes) || ! $diff->fromTable instanceof Table) {
return [];
}

$foreignKeys = [];
/** @var ForeignKeyConstraint[] $remainingForeignKeys */
$remainingForeignKeys = array_diff_key(
$diff->fromTable->getForeignKeys(),
$diff->removedForeignKeys
);

foreach ($remainingForeignKeys as $foreignKey) {
foreach ($diff->renamedIndexes as $index) {
if ($foreignKey->intersectsIndexColumns($index)) {
$foreignKeys[] = $foreignKey;

break;
}
}
}

return $foreignKeys;
}

/**
* {@inheritdoc}
*/
protected function getPostAlterTableIndexForeignKeySQL(TableDiff $diff): array
{
return array_merge(
parent::getPostAlterTableIndexForeignKeySQL($diff),
$this->getPostAlterTableRenameIndexForeignKeySQL($diff)
);
}

/**
* @param TableDiff $diff The table diff to gather the SQL for.
*
* @return string[]
*/
protected function getPostAlterTableRenameIndexForeignKeySQL(TableDiff $diff): array
{
$sql = [];
$newName = $diff->getNewName();

if ($newName !== null) {
$tableName = $newName->getQuotedName($this);
} else {
$tableName = $diff->getName($this)->getQuotedName($this);
}

foreach ($this->getRemainingForeignKeyConstraintsRequiringRenamedIndexes($diff) as $foreignKey) {
if (in_array($foreignKey, $diff->changedForeignKeys, true)) {
continue;
}

$sql[] = $this->getCreateForeignKeySQL($foreignKey, $tableName);
}

return $sql;
return [];
}

protected function getCreateIndexSQLFlags(Index $index): string
Expand Down Expand Up @@ -884,6 +796,7 @@ protected function initializeDoctrineTypeMappings(): void
'float' => 'float',
'int' => 'integer',
'integer' => 'integer',
'json' => 'json',
'longblob' => 'blob',
'longtext' => 'text',
'mediumblob' => 'blob',
Expand Down
20 changes: 0 additions & 20 deletions src/Platforms/Keywords/MariaDb102Keywords.php

This file was deleted.

0 comments on commit d8dc01f

Please sign in to comment.