[TASK] SchemaMigrator: Allow specifying index length for TEXT/BLOB columns 45/49745/3
authorMorton Jonuschat <m.jonuschat@mojocode.de>
Fri, 2 Sep 2016 10:13:43 +0000 (12:13 +0200)
committerSusanne Moog <susanne.moog@typo3.org>
Fri, 2 Sep 2016 14:37:20 +0000 (16:37 +0200)
Change-Id: I1121f4083553d8ab4231a254bd5f3b777e057b20
Resolves: #77777
Releases: master
Reviewed-on: https://review.typo3.org/49745
Tested-by: Bamboo TYPO3com <info@typo3.com>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Susanne Moog <susanne.moog@typo3.org>
Tested-by: Susanne Moog <susanne.moog@typo3.org>
typo3/sysext/core/Classes/Database/Schema/Parser/TableBuilder.php
typo3/sysext/core/Tests/Unit/Database/Schema/Fixtures/tablebuilder.sql
typo3/sysext/core/Tests/Unit/Database/Schema/Parser/TableBuilderTest.php

index fe3cb42..0a080f9 100644 (file)
@@ -178,6 +178,7 @@ class TableBuilder
      * @param \TYPO3\CMS\Core\Database\Schema\Parser\AST\CreateIndexDefinitionItem $item
      * @return \Doctrine\DBAL\Schema\Index
      * @throws \Doctrine\DBAL\Schema\SchemaException
+     * @throws \InvalidArgumentException
      */
     protected function addIndex(CreateIndexDefinitionItem $item): Index
     {
@@ -185,6 +186,9 @@ class TableBuilder
 
         $columnNames = array_map(
             function (IndexColumnName $columnName) {
+                if ($columnName->length) {
+                    return $columnName->columnName->schemaObjectName . '(' . $columnName->length . ')';
+                }
                 return $columnName->columnName->schemaObjectName;
             },
             $item->columnNames
@@ -192,17 +196,32 @@ class TableBuilder
 
         if ($item->isPrimary) {
             $this->table->setPrimaryKey($columnNames);
-        } elseif ($item->isUnique) {
-            $this->table->addUniqueIndex($columnNames, $indexName);
-        } elseif ($item->isFulltext) {
-            $this->table->addIndex($columnNames, $indexName, ['fulltext']);
-        } elseif ($item->isSpatial) {
-            $this->table->addIndex($columnNames, $indexName, ['spatial']);
+            $index = $this->table->getPrimaryKey();
         } else {
-            $this->table->addIndex($columnNames, $indexName);
-        }
+            $index = GeneralUtility::makeInstance(
+                Index::class,
+                $indexName,
+                $columnNames,
+                $item->isUnique,
+                $item->isPrimary
+            );
 
-        $index = $item->isPrimary ? $this->table->getPrimaryKey() : $this->table->getIndex($indexName);
+            if ($item->isFulltext) {
+                $index->addFlag('fulltext');
+            } elseif ($item->isSpatial) {
+                $index->addFlag('spatial');
+            }
+
+            $this->table = GeneralUtility::makeInstance(
+                Table::class,
+                $this->table->getName(),
+                $this->table->getColumns(),
+                array_merge($this->table->getIndexes(), [strtolower($indexName) => $index]),
+                $this->table->getForeignKeys(),
+                0,
+                $this->table->getOptions()
+            );
+        }
 
         return $index;
     }
index e873a4a..d542c72 100644 (file)
@@ -16,5 +16,6 @@ CREATE TABLE aTestTable (
        PRIMARY KEY (uid),
   UNIQUE `parent` (pid,`deleted`,sorting),
        KEY noCache (`no_cache`),
+       KEY substring (TSconfig(80)),
        FOREIGN KEY fk_overlay (uid) REFERENCES pages_language_overlay(pid)
 ) ENGINE = MyISAM DEFAULT CHARACTER SET latin1 COLLATE latin1_german_cs ROW_FORMAT DYNAMIC AUTO_INCREMENT=1;
index adcd5e2..7f5f671 100644 (file)
@@ -245,4 +245,13 @@ class TableBuilderTest extends UnitTestCase
         $this->assertSame('aTestTable', $subject->getLocalTableName());
         $this->assertSame('pages_language_overlay', $subject->getForeignTableName());
     }
+
+    /**
+     * @test
+     */
+    public function hasColumnLengthOnIndex()
+    {
+        $subject = $this->table->getIndex('substring');
+        $this->assertSame(['TSconfig(80)'], $subject->getColumns());
+    }
 }