Skip to content

Commit 07f31f0

Browse files
committed
Adjust index datastore alter test
1 parent 4da4675 commit 07f31f0

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

modules/datastore/src/DataDictionary/AlterTableQuery/MySQLQuery.php

+25-4
Original file line numberDiff line numberDiff line change
@@ -518,16 +518,37 @@ protected function buildAddIndexOptions(array $indexes, string $table, array $ty
518518
$add_index_options[] = "ADD {$mysql_index_type} INDEX {$name} ({$formatted_field_options}) COMMENT '{$comment}'";
519519
}
520520
if ($index_type == 'fulltext') {
521-
// Innodb only allows adding one fulltext index at a time.
522-
$command = $this->connection->prepareStatement("ALTER TABLE {$table} ADD {$mysql_index_type} INDEX {$name} ({$formatted_field_options}) COMMENT '{$comment}';", []);
523-
// Execute alter command.
524-
$command->execute();
521+
$this->executeFulltextAlter($table, $name, $formatted_field_options, $comment);
525522
}
526523
}
527524

528525
return $add_index_options;
529526
}
530527

528+
/**
529+
* Execute fulltext index table alters.
530+
*
531+
* @param string $table
532+
* Table name.
533+
* @param string $name
534+
* Index name.
535+
* @param string $formatted_field_options
536+
* Fields to be indexed.
537+
* @param string $comment
538+
* Description of the index.
539+
*/
540+
protected function executeFulltextAlter(string $table, string $name, string $formatted_field_options, string $comment): void {
541+
try {
542+
// Innodb only allows adding one fulltext index at a time.
543+
$command = $this->connection->prepareStatement("ALTER TABLE {$table} ADD FULLTEXT INDEX {$name} ({$formatted_field_options}) COMMENT '{$comment}';", []);
544+
// Execute alter command.
545+
$command->execute();
546+
}
547+
catch (\Throwable $e) {
548+
throw $e;
549+
}
550+
}
551+
531552
/**
532553
* Convert Frictionless to MySQL index types.
533554
*

modules/datastore/tests/src/Unit/DataDictionary/AlterTableQuery/MySQLQueryTest.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,9 @@ public function testExecute(): void {
122122
$this->assertEquals("ALTER TABLE {" . $table . "} MODIFY COLUMN foo TEXT COMMENT 'Foo', " .
123123
"MODIFY COLUMN bar DECIMAL(10, 5) COMMENT 'Bar', " .
124124
"MODIFY COLUMN baz DATE COMMENT 'Baz', " .
125-
"ADD INDEX index1 (foo (12), bar, baz) COMMENT 'Fizz', " .
126-
"ADD FULLTEXT INDEX index2 (foo (6), baz) COMMENT '';", $query);
125+
"ADD INDEX index1 (foo (12), bar, baz) COMMENT 'Fizz';", $query);
127126
}
128127

129-
130128
/**
131129
* Ensure alter fails when attempting to apply decimal type to large numbers.
132130
*/

0 commit comments

Comments
 (0)