[BUGFIX] Correctly create schema diff for renamed fields and indexes 87/58787/5
authorHelmut Hummel <typo3@helhum.io>
Mon, 29 Oct 2018 23:30:03 +0000 (00:30 +0100)
committerGeorg Ringer <georg.ringer@gmail.com>
Thu, 8 Nov 2018 20:55:57 +0000 (21:55 +0100)
TYPO3's schema migrator has code to create drop and add fields
statements out of renamed columns detected by doctrine.

This code however is never triggered, when using a MySQL connection
with tableoptions set, because then a new TableDiff object is created,
which does not contain the renamedColumns any more.

This fix tackles the issue in various places:

1. The charset is pulled out as well of the information_schema,
so that it is set in source and target schema objects and
table options stay the same for source and target schema.

2. The newly created table differences objects receive
the detected renamed columns and idexes.

Releases: master
Resolves: #86793
Change-Id: Iee6bc47ccf066cf9ccd7692af34e437e57695144
Reviewed-on: https://review.typo3.org/58787
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
typo3/sysext/core/Classes/Database/Schema/Comparator.php
typo3/sysext/core/Classes/Database/Schema/ConnectionMigrator.php

index cdaa44c..5ae80d2 100644 (file)
@@ -69,6 +69,8 @@ class Comparator extends \Doctrine\DBAL\Schema\Comparator
             $tableDifferences = GeneralUtility::makeInstance(TableDiff::class, $fromTable->getName());
             $tableDifferences->fromTable = $fromTable;
         } else {
+            $renamedColumns = $tableDifferences->renamedColumns;
+            $renamedIndexes = $tableDifferences->renamedIndexes;
             // Rebuild TableDiff with enhanced TYPO3 TableDiff class
             $tableDifferences = GeneralUtility::makeInstance(
                 TableDiff::class,
@@ -81,6 +83,8 @@ class Comparator extends \Doctrine\DBAL\Schema\Comparator
                 $tableDifferences->removedIndexes,
                 $tableDifferences->fromTable
             );
+            $tableDifferences->renamedColumns = $renamedColumns;
+            $tableDifferences->renamedIndexes = $renamedIndexes;
         }
 
         // Set the table options to be parsed in the AlterTable event.
index 3fae5cb..40f3caa 100644 (file)
@@ -1173,13 +1173,23 @@ class ConnectionMigrator
         $queryBuilder = $this->connection->createQueryBuilder();
         $result = $queryBuilder
             ->select(
-                'TABLE_NAME AS table',
-                'ENGINE AS engine',
-                'ROW_FORMAT AS row_format',
-                'TABLE_COLLATION AS collate',
-                'TABLE_COMMENT AS comment'
+                'tables.TABLE_NAME AS table',
+                'tables.ENGINE AS engine',
+                'tables.ROW_FORMAT AS row_format',
+                'tables.TABLE_COLLATION AS collate',
+                'tables.TABLE_COMMENT AS comment',
+                'CCSA.character_set_name AS charset'
+            )
+            ->from('information_schema.TABLES', 'tables')
+            ->join(
+                'tables',
+                'information_schema.COLLATION_CHARACTER_SET_APPLICABILITY',
+                'CCSA',
+                $queryBuilder->expr()->eq(
+                    'CCSA.collation_name',
+                    $queryBuilder->quoteIdentifier('tables.table_collation')
+                )
             )
-            ->from('information_schema.TABLES')
             ->where(
                 $queryBuilder->expr()->eq(
                     'TABLE_TYPE',