Skip to content

Commit

Permalink
merge MySQL 5.7.9 (GA) semantics into MySQL57Platform
Browse files Browse the repository at this point in the history
  • Loading branch information
deeky666 committed Feb 9, 2017
1 parent 0bd7781 commit 1412157
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 8 deletions.
8 changes: 8 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ you are using a URL-style DSN and have a username, password or database name con
percentage sign, you need to update your DSN. If your password is, say, ``foo%foo``, it
should be encoded as ``foo%25foo``.

## MINOR BC BREAK: Native JSON type support in MySQL 5.7 platform

MySQL 5.7 ships with native JSON type support which now is adopted by DBAL.
If you are using MySQL 5.7 and have columns with ``json_array`` type defined in your database,
utilizing DBAL's schema comparator will cause a schema diff, where the previously used native type
``LONGTEXT`` will be changed to ``JSON``.
This might cause migration issues if the particular column contains invalid JSON values.

# Upgrade to 2.5.1

## MINOR BC BREAK: Doctrine\DBAL\Schema\Table
Expand Down
2 changes: 1 addition & 1 deletion docs/en/reference/platforms.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ MySQL
^^^^^

- ``MySqlPlatform`` for version 5.0 and above.
- ``MySQL57Platform`` for version 5.7 and above.
- ``MySQL57Platform`` for version 5.7 (5.7.9 GA) and above.

Oracle
^^^^^^
Expand Down
11 changes: 8 additions & 3 deletions lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,15 @@ public function createDatabasePlatformForVersion($version)

$majorVersion = $versionParts['major'];
$minorVersion = isset($versionParts['minor']) ? $versionParts['minor'] : 0;
$patchVersion = isset($versionParts['patch']) ? $versionParts['patch'] : 0;
$version = $majorVersion . '.' . $minorVersion . '.' . $patchVersion;
$patchVersion = isset($versionParts['patch']) ? $versionParts['patch'] : null;

if (version_compare($version, '5.7', '>=')) {
if ($majorVersion === '5' && $minorVersion === '7' && null === $patchVersion) {
$patchVersion = '9';
}

$version = $majorVersion . '.' . $minorVersion . '.' . $patchVersion;

if (version_compare($version, '5.7.9', '>=')) {
return new MySQL57Platform();
}

Expand Down
5 changes: 4 additions & 1 deletion lib/Doctrine/DBAL/Platforms/Keywords/MySQL57Keywords.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ protected function getKeywords()
'FOREIGN',
'FROM',
'FULLTEXT',
'GENERATED',
'GET',
'GRANT',
'GROUP',
Expand Down Expand Up @@ -183,12 +184,12 @@ protected function getKeywords()
'MODIFIES',
'NATURAL',
'NO_WRITE_TO_BINLOG',
'NONBLOCKING',
'NOT',
'NULL',
'NUMERIC',
'ON',
'OPTIMIZE',
'OPTIMIZER_COSTS',
'OPTION',
'OPTIONALLY',
'OR',
Expand Down Expand Up @@ -241,6 +242,7 @@ protected function getKeywords()
'SSL',
'STARTING',
'STRAIGHT_JOIN',
'STORED',
'TABLE',
'TERMINATED',
'THEN',
Expand Down Expand Up @@ -268,6 +270,7 @@ protected function getKeywords()
'VARCHAR',
'VARCHARACTER',
'VARYING',
'VIRTUAL',
'WHEN',
'WHERE',
'WHILE',
Expand Down
29 changes: 28 additions & 1 deletion lib/Doctrine/DBAL/Platforms/MySQL57Platform.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,31 @@
use Doctrine\DBAL\Schema\TableDiff;

/**
* Provides the behavior, features and SQL dialect of the MySQL 5.7 database platform.
* Provides the behavior, features and SQL dialect of the MySQL 5.7 (5.7.9 GA) database platform.
*
* @author İsmail BASKIN <[email protected]>
* @author Steve Müller <[email protected]>
* @link www.doctrine-project.org
* @since 2.5
*/
class MySQL57Platform extends MySqlPlatform
{
/**
* {@inheritdoc}
*/
public function hasNativeJsonType()
{
return true;
}

/**
* {@inheritdoc}
*/
public function getJsonTypeDeclarationSQL(array $field)
{
return 'JSON';
}

/**
* {@inheritdoc}
*/
Expand Down Expand Up @@ -64,4 +81,14 @@ protected function getReservedKeywordsClass()
{
return 'Doctrine\DBAL\Platforms\Keywords\MySQL57Keywords';
}

/**
* {@inheritdoc}
*/
protected function initializeDoctrineTypeMappings()
{
parent::initializeDoctrineTypeMappings();

$this->doctrineTypeMapping['json'] = 'json_array';
}
}
6 changes: 4 additions & 2 deletions tests/Doctrine/Tests/DBAL/Driver/AbstractMySQLDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ protected function getDatabasePlatformsForVersions()
return array(
array('5.6.9', 'Doctrine\DBAL\Platforms\MySqlPlatform'),
array('5.7', 'Doctrine\DBAL\Platforms\MySQL57Platform'),
array('5.7.0', 'Doctrine\DBAL\Platforms\MySQL57Platform'),
array('5.7.1', 'Doctrine\DBAL\Platforms\MySQL57Platform'),
array('5.7.0', 'Doctrine\DBAL\Platforms\MySqlPlatform'),
array('5.7.8', 'Doctrine\DBAL\Platforms\MySqlPlatform'),
array('5.7.9', 'Doctrine\DBAL\Platforms\MySQL57Platform'),
array('5.7.10', 'Doctrine\DBAL\Platforms\MySQL57Platform'),
array('6', 'Doctrine\DBAL\Platforms\MySQL57Platform'),
array('10.0.15-MariaDB-1~wheezy', 'Doctrine\DBAL\Platforms\MySqlPlatform'),
array('10.1.2a-MariaDB-a1~lenny-log', 'Doctrine\DBAL\Platforms\MySqlPlatform'),
Expand Down
16 changes: 16 additions & 0 deletions tests/Doctrine/Tests/DBAL/Platforms/MySQL57PlatformTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,22 @@ public function createPlatform()
return new MySQL57Platform();
}

public function testHasNativeJsonType()
{
$this->assertTrue($this->_platform->hasNativeJsonType());
}

public function testReturnsJsonTypeDeclarationSQL()
{
$this->assertSame('JSON', $this->_platform->getJsonTypeDeclarationSQL(array()));
}

public function testInitializesJsonTypeMapping()
{
$this->assertTrue($this->_platform->hasDoctrineTypeMappingFor('json'));
$this->assertEquals('json_array', $this->_platform->getDoctrineTypeMapping('json'));
}

/**
* @group DBAL-234
*/
Expand Down

0 comments on commit 1412157

Please sign in to comment.