diff --git a/common/framework/parsers/dbtable/index.php b/common/framework/parsers/dbtable/index.php index f0fc0d7b7..fddd75fe1 100644 --- a/common/framework/parsers/dbtable/index.php +++ b/common/framework/parsers/dbtable/index.php @@ -9,5 +9,5 @@ class Index { public $name; public $columns = array(); - public $is_unique = false; + public $type = null; } diff --git a/common/framework/parsers/dbtable/table.php b/common/framework/parsers/dbtable/table.php index b5f7cd4ad..d35183586 100644 --- a/common/framework/parsers/dbtable/table.php +++ b/common/framework/parsers/dbtable/table.php @@ -90,7 +90,7 @@ class Table } $idxcolumns[] = '`' . $column_name . '`' . ($prefix_size > 0 ? "($prefix_size)" : ''); } - $idxtype = ($index->is_unique ? 'UNIQUE' : 'INDEX'); + $idxtype = $index->type ? ($index->type . ' INDEX') : 'INDEX'; $idxdef = ' ' . $idxtype . ' `' . $index->name . '` (' . implode(', ', $idxcolumns) . ')'; $columns[] = $idxdef; } diff --git a/common/framework/parsers/dbtableparser.php b/common/framework/parsers/dbtableparser.php index 1d1b395b5..2ed0e854f 100644 --- a/common/framework/parsers/dbtableparser.php +++ b/common/framework/parsers/dbtableparser.php @@ -154,11 +154,19 @@ class DBTableParser extends BaseParser $index->columns[$idxcolumn] = 0; } } - $index->is_unique = toBool($index_info['unique'] ?? ''); + + if (isset($index_info['type']) && $index_info['type']) + { + $index->type = strtoupper($index_info['type']); + } + elseif (toBool($index_info['unique'])) + { + $index->type = 'UNIQUE'; + } if (isset($table->columns[$idxcolumn]) && is_object($table->columns[$idxcolumn])) { $table->columns[$idxcolumn]->is_indexed = true; - $table->columns[$idxcolumn]->is_unique = $index->is_unique; + $table->columns[$idxcolumn]->is_unique = $index->type === 'UNIQUE'; } $table->indexes[$index->name] = $index; } diff --git a/tests/_data/dbtable/example.xml b/tests/_data/dbtable/example.xml index e10b7c6b2..3ac947e6b 100644 --- a/tests/_data/dbtable/example.xml +++ b/tests/_data/dbtable/example.xml @@ -4,11 +4,14 @@ + - + + + diff --git a/tests/unit/framework/parsers/DBTableParserTest.php b/tests/unit/framework/parsers/DBTableParserTest.php index efdb67bfa..aac06c5a2 100644 --- a/tests/unit/framework/parsers/DBTableParserTest.php +++ b/tests/unit/framework/parsers/DBTableParserTest.php @@ -17,11 +17,15 @@ class DBTableParserTest extends \Codeception\TestCase\Test $this->assertEquals('number', $table->columns['module_srl']->xetype); $this->assertTrue($table->columns['module_srl']->is_indexed); $this->assertTrue($table->columns['list_order']->is_unique); + $this->assertFalse($table->columns['geometry']->is_unique); - $this->assertEquals(6, count($table->indexes)); + $this->assertEquals(8, count($table->indexes)); $this->assertEquals(['module_srl' => 0, 'document_srl' => 0], $table->indexes['idx_module_document_srl']->columns); $this->assertEquals(['status' => 6], $table->indexes['idx_status']->columns); - $this->assertTrue($table->indexes['unique_list_order']->is_unique); + $this->assertEquals('UNIQUE', $table->indexes['unique_list_order']->type); + $this->assertEquals('SPATIAL', $table->indexes['spatial_geometry']->type); + $this->assertEquals('FULLTEXT', $table->indexes['fulltext_description']->type); + $this->assertNull($table->indexes['idx_comment_srl']->type); $this->assertEquals(2, count($table->constraints)); $this->assertEquals('FOREIGN KEY', $table->constraints[0]->type); @@ -44,7 +48,9 @@ class DBTableParserTest extends \Codeception\TestCase\Test $this->assertContains('INDEX `idx_document_srl` (`document_srl`),', $sql); $this->assertContains('INDEX `idx_module_document_srl` (`module_srl`, `document_srl`),', $sql); $this->assertContains('INDEX `idx_status` (`status`(6)),', $sql); - $this->assertContains('UNIQUE `unique_list_order` (`list_order`),', $sql); + $this->assertContains('UNIQUE INDEX `unique_list_order` (`list_order`),', $sql); + $this->assertContains('SPATIAL INDEX `spatial_geometry` (`geometry`),', $sql); + $this->assertContains('FULLTEXT INDEX `fulltext_description` (`description`),', $sql); $this->assertContains('FOREIGN KEY (`module_srl`) REFERENCES `rx_module` (`module_srl`) ON DELETE CASCADE ON UPDATE RESTRICT', $sql); $this->assertContains('CHECK (list_order < 0)', $sql); $this->assertContains('CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci', $sql);