Actions
Bug #76508
closedComparison of NOT NULL fields without a default value does not work in "Compare Database" tool if a field is not autoincrement
Status:
Closed
Priority:
Must have
Assignee:
-
Category:
Install Tool
Target version:
-
Start date:
2016-06-07
Due date:
% Done:
100%
Estimated time:
1.00 h
TYPO3 Version:
7
PHP Version:
5.6
Tags:
Complexity:
easy
Is Regression:
No
Sprint Focus:
Description
In some cases you would like to have a field which should never be NULL, eg. a referencing ID to parent object. But if a database field is defined as NOT NULL field without a default value the comparison does not work because the tool expects NULL as default value. A default of '0' would work but allows inserting of rows without the specific field explicit set.
For example the SQL definition looks like that:
CREATE TABLE tx_foo ( uid int(11) unsigned NOT NULL auto_increment, pid int(11) unsigned DEFAULT '0' NOT NULL, tstamp int(11) unsigned DEFAULT '0' NOT NULL, crdate int(11) unsigned DEFAULT '0' NOT NULL, someid int(11) unsigned NOT NULL, PRIMARY KEY (uid), KEY parent (pid), KEY someid (someid) ) ENGINE=InnoDB;
The install tool will always show a difference for the "someid" field and expects:
someid int(11) unsigned DEFAULT NULL NOT NULL,
But this would result in invalid SQL when creating the table.
So the SqlSchemaMigrationService should be modified to prevent this edge case:
LINE 517 in SqlSchemaMigrationService.php (assembleFieldDefinition method)
// Add a default value if the field is not auto-incremented (these fields never have a default definition) // but not if the field can not be NULL and default value is NULL (this results in invalid SQL) if (!stristr($row['Extra'], 'auto_increment') && !($row['Null'] == 'NO' && $row['Default'] === NULL)) {
Actions