[TASK] Add support for SPATIAL index type 53/38953/7
authorMorton Jonuschat <m.jonuschat@mojocode.de>
Mon, 27 Apr 2015 10:55:55 +0000 (12:55 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Fri, 8 May 2015 20:51:32 +0000 (22:51 +0200)
Add support for "SPATIAL" keys to the SqlSchemaMigrationService.

Ignoring the subpart/key length for this type of index is required as
MySQL does not support specifying the length when creating/modifying
the index but reports this information when retrieving keys for a
table.

This change has been verified against MySQL 5.5.42 (Mac OS X) as well
as Percona Server 5.6.23 (Release 72.1, Linux).

Resolves: #65354
Releases: master
Change-Id: I2a2d0d1e7eddb6ff8fcfb50d88936669e64ea309
Reviewed-on: http://review.typo3.org/38953
Reviewed-by: Stephan Großberndt <stephan@grossberndt.de>
Tested-by: Stephan Großberndt <stephan@grossberndt.de>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/install/Classes/Service/SqlSchemaMigrationService.php
typo3/sysext/install/Tests/Unit/Service/SqlSchemaMigrationServiceTest.php

index 3ca5509..985b6ed 100644 (file)
@@ -107,7 +107,7 @@ class SqlSchemaMigrationService {
                                        $lineV = preg_replace('/\h+/', ' ', $lineV);
                                        $parts = explode(' ', $lineV, 2);
                                        // Field definition
-                                       if (!preg_match('/(PRIMARY|UNIQUE|FULLTEXT|INDEX|KEY)/', $parts[0])) {
+                                       if (!preg_match('/(PRIMARY|UNIQUE|FULLTEXT|SPATIAL|INDEX|KEY)/', $parts[0])) {
                                                // Make sure there is no default value when auto_increment is set
                                                if (stristr($parts[1], 'auto_increment')) {
                                                        $parts[1] = preg_replace('/ default \'0\'/i', '', $parts[1]);
@@ -123,10 +123,10 @@ class SqlSchemaMigrationService {
                                                $total[$table]['fields'][$key] = $parts[1];
                                        } else {
                                                // Key definition
-                                               $search = array('/UNIQUE (INDEX|KEY)/', '/FULLTEXT (INDEX|KEY)/', '/INDEX/');
-                                               $replace = array('UNIQUE', 'FULLTEXT', 'KEY');
+                                               $search = array('/UNIQUE (INDEX|KEY)/', '/FULLTEXT (INDEX|KEY)/', '/SPATIAL (INDEX|KEY)/', '/INDEX/');
+                                               $replace = array('UNIQUE', 'FULLTEXT', 'SPATIAL', 'KEY');
                                                $lineV = preg_replace($search, $replace, $lineV);
-                                               if (preg_match('/PRIMARY|UNIQUE|FULLTEXT/', $parts[0])) {
+                                               if (preg_match('/PRIMARY|UNIQUE|FULLTEXT|SPATIAL/', $parts[0])) {
                                                        $parts[1] = preg_replace('/^(KEY|INDEX) /', '', $parts[1]);
                                                }
                                                $newParts = explode(' ', $parts[1], 2);
@@ -190,15 +190,17 @@ class SqlSchemaMigrationService {
                        foreach ($keyInformation as $keyRow) {
                                $keyName = $keyRow['Key_name'];
                                $colName = $keyRow['Column_name'];
-                               if ($keyRow['Sub_part']) {
+                               if ($keyRow['Sub_part'] && $keyRow['Index_type'] !== 'SPATIAL') {
                                        $colName .= '(' . $keyRow['Sub_part'] . ')';
                                }
                                $tempKeys[$tableName][$keyName][$keyRow['Seq_in_index']] = $colName;
                                if ($keyName == 'PRIMARY') {
                                        $prefix = 'PRIMARY KEY';
                                } else {
-                                       if ($keyRow['Index_type'] == 'FULLTEXT') {
+                                       if ($keyRow['Index_type'] === 'FULLTEXT') {
                                                $prefix = 'FULLTEXT';
+                                       } elseif ($keyRow['Index_type'] === 'SPATIAL') {
+                                               $prefix = 'SPATIAL';
                                        } elseif ($keyRow['Non_unique']) {
                                                $prefix = 'KEY';
                                        } else {
index 61dd4e5..179a501 100644 (file)
@@ -249,6 +249,42 @@ class SqlSchemaMigrationServiceTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
        /**
         * @test
         */
+       public function getDatabaseExtraFindsNewSpatialKeys() {
+               $subject = new SqlSchemaMigrationService();
+               $differenceArray = $subject->getDatabaseExtra(
+                       array(
+                               'tx_foo' => array(
+                                       'keys' => array(
+                                               'foo' => 'SPATIAL foo (foo)'
+                                       )
+                               )
+                       ),
+                       array(
+                               'tx_foo' => array(
+                                       'keys' => array()
+                               )
+                       )
+               );
+
+               $this->assertEquals(
+                       $differenceArray,
+                       array(
+                               'extra' => array(
+                                       'tx_foo' => array(
+                                               'keys' => array(
+                                                       'foo' => 'SPATIAL foo (foo)'
+                                               )
+                                       )
+                               ),
+                               'diff' => array(),
+                               'diff_currentValues' => NULL
+                       )
+               );
+       }
+
+       /**
+        * @test
+        */
        public function checkColumnDefinitionIfCommentIsSupplied() {
                $subject = new SqlSchemaMigrationService();
                $fieldDefinition = $subject->assembleFieldDefinition(