Commit 58d225b4 authored by Morton Jonuschat's avatar Morton Jonuschat Committed by Christian Kuhn
Browse files

[TASK] dbal: Ignore MySQL UNSIGNED/ZEROFILL in database schema compare

Avoid suggestions for database alterations in the install tool
that can not be implemented on DBMS other than MySQL due to
usage of non-standard attributes.

Resolves: #67335
Releases: master
Change-Id: I749563e0b0abc9b42236f2951222cb2771507a79
Reviewed-on: http://review.typo3.org/40137

Reviewed-by: Andreas Fernandez's avatarAndreas Fernandez <typo3@scripting-base.de>
Tested-by: Andreas Fernandez's avatarAndreas Fernandez <typo3@scripting-base.de>
Reviewed-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
parent a49cdd2f
......@@ -284,6 +284,11 @@ class SqlSchemaMigrationService {
$fieldC
);
// Ignore nonstandard MySQL numeric field attributes UNSIGNED and ZEROFILL
if ($this->isDbalEnabled() && preg_match('/^(TINYINT|SMALLINT|MEDIUMINT|INT|INTEGER|BIGINT|REAL|DOUBLE|FLOAT|DECIMAL|NUMERIC)\([^\)]+\)\s+(UNSIGNED|ZEROFILL)/i', $fieldC)) {
$fieldC = str_ireplace(array(' UNSIGNED', ' ZEROFILL'), '', $fieldC);
$FDcomp[$table][$theKey][$fieldN] = str_ireplace(array(' UNSIGNED', ' ZEROFILL'), '', $FDcomp[$table][$theKey][$fieldN]);
}
if ($ignoreNotNullWhenComparing) {
$fieldC = str_replace(' NOT NULL', '', $fieldC);
$FDcomp[$table][$theKey][$fieldN] = str_replace(' NOT NULL', '', $FDcomp[$table][$theKey][$fieldN]);
......
......@@ -437,4 +437,93 @@ class SqlSchemaMigrationServiceTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
);
}
/**
* @test
*/
public function getDatabaseExtraIncludesUnsignedAttributeIfMySQLIsUsed() {
$subject = $this->getAccessibleMock(SqlSchemaMigrationService::class, array('isDbalEnabled'), array(), '', FALSE);
$subject->expects($this->any())->method('isDbalEnabled')->will($this->returnValue(FALSE));
$differenceArray = $subject->getDatabaseExtra(
array(
'tx_foo' => array(
'fields' => array(
'foo' => 'INT(11) UNSIGNED DEFAULT \'0\' NOT NULL',
),
'extra' => array(
'ENGINE' => 'InnoDB'
)
)
),
array(
'tx_foo' => array(
'fields' => array(
'foo' => 'int(11) DEFAULT \'0\' NOT NULL',
),
'extra' => array(
'ENGINE' => 'InnoDB'
)
)
)
);
$this->assertSame(
$differenceArray,
array(
'extra' => array(),
'diff' => array(
'tx_foo' => array(
'fields' => array(
'foo' => 'int(11) UNSIGNED DEFAULT \'0\' NOT NULL',
),
)
),
'diff_currentValues' => array(
'tx_foo' => array(
'fields' => array(
'foo' => 'int(11) DEFAULT \'0\' NOT NULL',
),
)
)
)
);
}
/**
* @test
*/
public function getDatabaseExtraExcludesUnsignedAttributeIfDbalIsUsed() {
$subject = $this->getAccessibleMock(SqlSchemaMigrationService::class, array('isDbalEnabled'), array(), '', FALSE);
$subject->expects($this->any())->method('isDbalEnabled')->will($this->returnValue(TRUE));
$differenceArray = $subject->getDatabaseExtra(
array(
'tx_foo' => array(
'fields' => array(
'foo' => 'INT(11) UNSIGNED DEFAULT \'0\' NOT NULL',
),
'extra' => array(
'ENGINE' => 'InnoDB'
)
)
),
array(
'tx_foo' => array(
'fields' => array(
'foo' => 'int(11) DEFAULT \'0\' NOT NULL',
),
'extra' => array(
'ENGINE' => 'InnoDB'
)
)
)
);
$this->assertSame(
$differenceArray,
array(
'extra' => array(),
'diff' => array(),
'diff_currentValues' => NULL
)
);
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment