Project

General

Profile

Actions

Bug #76508

closed

Comparison of NOT NULL fields without a default value does not work in "Compare Database" tool if a field is not autoincrement

Added by M. Stichweh almost 8 years ago. Updated over 5 years ago.

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)) {


Related issues 2 (0 open2 closed)

Related to TYPO3 Core - Bug #76641: Database compare and "NULL default NULL" is not recognizedClosed2016-06-15

Actions
Related to TYPO3 Core - Feature #77643: Reimplement SqlSchemaMigrationService using SchemaManagerClosedMorton Jonuschat2016-08-25

Actions
Actions #1

Updated by Morton Jonuschat almost 8 years ago

  • Status changed from New to Needs Feedback
someid int(11) unsigned DEFAULT NULL NOT NULL,
is the definition reported by MySQL for that field (the MySQL server adds the implicit default value), so if you add the full definition of the column to your ext_tables.sql file everything should be ok.
Actions #2

Updated by M. Stichweh almost 8 years ago

Morton Jonuschat wrote:

[...] is the definition reported by MySQL for that field (the MySQL server adds the implicit default value), so if you add the full definition of the column to your ext_tables.sql file everything should be ok.

This is correct, if I define the "someid" field in this way in my ext_tables.sql, the compare tool works properly. But when the table is created the first time I get a MySQL (MariaDB) error:

#1067 - Invalid default value for 'someid'

Because of that I cannot define the field like that and the compare tool will always show a difference. This is a problem when updating Typo3 for example since the database update step of the migration wizard will never succeed.

Actions #3

Updated by Gerrit Code Review over 7 years ago

  • Status changed from Needs Feedback to Under Review

Patch set 12 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/49593

Actions #4

Updated by Gerrit Code Review over 7 years ago

Patch set 13 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/49593

Actions #5

Updated by Gerrit Code Review over 7 years ago

Patch set 14 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/49593

Actions #6

Updated by Gerrit Code Review over 7 years ago

Patch set 15 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/49593

Actions #7

Updated by Morton Jonuschat over 7 years ago

  • Status changed from Under Review to Resolved
  • % Done changed from 0 to 100
Actions #8

Updated by Benni Mack over 5 years ago

  • Status changed from Resolved to Closed
Actions

Also available in: Atom PDF