[FEATURE] Reflect mysql comments in SchemaMigrator 78/21478/7
authorNico de Haen <mail@ndh-websolutions.de>
Sun, 18 Jan 2015 14:30:34 +0000 (15:30 +0100)
committerAlexander Opitz <opitz.alexander@googlemail.com>
Mon, 19 Jan 2015 15:15:15 +0000 (16:15 +0100)
This enables that the database migration and
comparison process includes mysql column comments.

Resolves: #49060
Releases: master

Change-Id: I8785690496bbc4fa80a8bf98ca75029c48f500f9
Reviewed-on: http://review.typo3.org/21478
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Reviewed-by: Oliver Klee <typo3-coding@oliverklee.de>
Reviewed-by: Alexander Opitz <opitz.alexander@googlemail.com>
Tested-by: Alexander Opitz <opitz.alexander@googlemail.com>
typo3/sysext/core/Classes/Database/DatabaseConnection.php
typo3/sysext/core/Documentation/Changelog/master/Feature-49060-MySqlCommentsShownInSchemaMigrator.rst [new file with mode: 0644]
typo3/sysext/install/Classes/Service/SqlSchemaMigrationService.php
typo3/sysext/install/Tests/Unit/Service/SqlSchemaMigrationServiceTest.php

index db7a72d..d587178 100644 (file)
@@ -1345,7 +1345,7 @@ class DatabaseConnection {
         */
        public function admin_get_fields($tableName) {
                $output = array();
-               $columns_res = $this->query('SHOW COLUMNS FROM `' . $tableName . '`');
+               $columns_res = $this->query('SHOW FULL COLUMNS FROM `' . $tableName . '`');
                if ($columns_res !== FALSE) {
                        while ($fieldRow = $columns_res->fetch_assoc()) {
                                $output[$fieldRow['Field']] = $fieldRow;
diff --git a/typo3/sysext/core/Documentation/Changelog/master/Feature-49060-MySqlCommentsShownInSchemaMigrator.rst b/typo3/sysext/core/Documentation/Changelog/master/Feature-49060-MySqlCommentsShownInSchemaMigrator.rst
new file mode 100644 (file)
index 0000000..6ad87aa
--- /dev/null
@@ -0,0 +1,12 @@
+============================================================
+Feature: #49060 - MySql Comments reflected in SchemaMigrator
+============================================================
+
+Description
+===========
+
+Comments in the *.sql files are stored the database table and shown
+by the Schema Migration Feature in Install Tool.
+
+Existing comments are overriden with changes provided by other extensions.
+
index 3d0f71c..24fe8c8 100644 (file)
@@ -491,6 +491,9 @@ class SqlSchemaMigrationService {
                if ($row['Extra']) {
                        $field[] = $row['Extra'];
                }
+               if (trim($row['Comment']) !== '') {
+                       $field[] = "COMMENT '" . $row['Comment'] . "'";
+               }
                return implode(' ', $field);
        }
 
index 2500ff2..f23b5d3 100644 (file)
@@ -101,14 +101,14 @@ class SqlSchemaMigrationServiceTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                        array(
                                'tx_foo' => array(
                                        'fields' => array(
-                                               'foo' => 'INT(11) DEFAULT \'0\' NOT NULL'
+                                               'foo' => 'INT(11) DEFAULT \'0\' NOT NULL',
                                        )
                                )
                        ),
                        array(
                                'tx_foo' => array(
                                        'fields' => array(
-                                               'foo' => 'int(11) DEFAULT \'0\' NOT NULL'
+                                               'foo' => 'int(11) DEFAULT \'0\' NOT NULL',
                                        )
                                )
                        )
@@ -120,7 +120,7 @@ class SqlSchemaMigrationServiceTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                        array(
                                'extra' => array(),
                                'diff' => array(),
-                               'diff_currentValues' => NULL
+                               'diff_currentValues' => NULL,
                        )
                );
        }
@@ -134,14 +134,14 @@ class SqlSchemaMigrationServiceTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                        array(
                                'tx_foo' => array(
                                        'fields' => array(
-                                               'PRIMARY KEY (md5hash)'
+                                               'PRIMARY KEY (md5hash)',
                                        )
                                )
                        ),
                        array(
                                'tx_foo' => array(
                                        'fields' => array(
-                                               'PRIMARY KEY (md5hash)')
+                                               'PRIMARY KEY (md5hash)'),
                                )
                        )
                );
@@ -152,9 +152,56 @@ class SqlSchemaMigrationServiceTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                        array(
                                'extra' => array(),
                                'diff' => array(),
-                               'diff_currentValues' => NULL
+                               'diff_currentValues' => NULL,
                        )
                );
        }
 
+       /**
+        * @test
+        */
+       public function checkColumnDefinitionIfCommentIsSupplied() {
+               $subject = new SqlSchemaMigrationService();
+               $fieldDefinition = $subject->assembleFieldDefinition(
+                       array(
+                               'Field' => 'uid',
+                               'Type' => 'int(11)',
+                               'Null' => 'NO',
+                               'Key' => 'PRI',
+                               'Default' => NULL,
+                               'Extra' => 'auto_increment',
+                               'Comment' => 'I am a comment',
+                       )
+               );
+
+
+               $this->assertSame(
+                       'int(11) NOT NULL auto_increment COMMENT \'I am a comment\'',
+                       $fieldDefinition
+               );
+       }
+
+       /**
+        * @test
+        */
+       public function checkColumnDefinitionIfNoCommentIsSupplied() {
+               $subject = new SqlSchemaMigrationService();
+               $fieldDefinition = $subject->assembleFieldDefinition(
+                       array(
+                               'Field' => 'uid',
+                               'Type' => 'int(11)',
+                               'Null' => 'NO',
+                               'Key' => 'PRI',
+                               'Default' => NULL,
+                               'Extra' => 'auto_increment',
+                       )
+               );
+
+
+               $this->assertSame(
+                       'int(11) NOT NULL auto_increment',
+                       $fieldDefinition
+               );
+       }
+
 }