[BUGFIX] Doctrine: Fix SchemaMigrator renaming columns instead of adding 87/49787/3
authorMorton Jonuschat <m.jonuschat@mojocode.de>
Fri, 2 Sep 2016 19:56:49 +0000 (21:56 +0200)
committerJan Helke <typo3@helke.de>
Fri, 2 Sep 2016 20:29:40 +0000 (22:29 +0200)
When a partial SQL file doesn't include an existing column that is exactly
the same configuration as a new column the Doctrine SchemaManager falsely
detects a column rename. Convert these renamed columns to newly added columns.

Change-Id: Iad7590b3cb47c8abc4864f1e19e305475e4a27f4
Releases: master
Resolves: #77804
Reviewed-on: https://review.typo3.org/49787
Tested-by: Marco Bresch <marco.bresch@starfinanz.de>
Reviewed-by: Marco Bresch <marco.bresch@starfinanz.de>
Reviewed-by: Jan Helke <typo3@helke.de>
Tested-by: Jan Helke <typo3@helke.de>
typo3/sysext/core/Classes/Database/Schema/SchemaMigrator.php
typo3/sysext/extensionmanager/Classes/Utility/InstallUtility.php

index 4627bf4..6d2c05a 100644 (file)
@@ -209,6 +209,20 @@ class SchemaMigrator
             foreach ($schemaDiff->changedTables as $key => $changedTable) {
                 $schemaDiff->changedTables[$key]->removedColumns = [];
                 $schemaDiff->changedTables[$key]->removedIndexes = [];
+
+                // With partial ext_tables.sql files the SchemaManager is detecting
+                // existing columns as false positives for a column rename. In this
+                // context every rename is actually a new column.
+                foreach ($changedTable->renamedColumns as $columnName => $renamedColumn) {
+                    $changedTable->addedColumns[$renamedColumn->getName()] = GeneralUtility::makeInstance(
+                        Column::class,
+                        $renamedColumn->getName(),
+                        $renamedColumn->getType(),
+                        array_diff_key($renamedColumn->toArray(), ['name', 'type'])
+                    );
+                    unset($changedTable->renamedColumns[$columnName]);
+                }
+
                 if ($createOnly) {
                     $schemaDiff->changedTables[$key]->changedColumns = [];
                     $schemaDiff->changedTables[$key]->renamedIndexes = [];
index 631c3af..f08f792 100644 (file)
@@ -474,7 +474,6 @@ class InstallUtility implements \TYPO3\CMS\Core\SingletonInterface
     {
         $sqlReader = GeneralUtility::makeInstance(SqlReader::class);
         $statements = $sqlReader->getCreateTableStatementArray($rawDefinitions);
-
         if (count($statements) !== 0) {
             $schemaMigrationService = GeneralUtility::makeInstance(SchemaMigrator::class);
             $schemaMigrationService->install($statements);