Skip to content

Commit 83ee8b1

Browse files
authored
Merge pull request #1394 from garas/add-multiple-fulltext
Add FULLTEXT indexes on MySQL one at a time
2 parents 9b346e0 + 7223d32 commit 83ee8b1

File tree

2 files changed

+42
-5
lines changed

2 files changed

+42
-5
lines changed

src/Phinx/Db/Adapter/MysqlAdapter.php

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -523,12 +523,28 @@ public function hasIndexByName($tableName, $indexName)
523523
*/
524524
protected function getAddIndexInstructions(Table $table, Index $index)
525525
{
526-
$alter = sprintf(
527-
'ADD %s',
528-
$this->getIndexSqlDefinition($index)
529-
);
526+
$instructions = new AlterInstructions();
530527

531-
return new AlterInstructions([$alter]);
528+
if ($index->getType() == Index::FULLTEXT) {
529+
// Must be executed separately
530+
// SQLSTATE[HY000]: General error: 1795 InnoDB presently supports one FULLTEXT index creation at a time
531+
$alter = sprintf(
532+
'ALTER TABLE %s ADD %s',
533+
$this->quoteTableName($table->getName()),
534+
$this->getIndexSqlDefinition($index)
535+
);
536+
537+
$instructions->addPostStep($alter);
538+
} else {
539+
$alter = sprintf(
540+
'ADD %s',
541+
$this->getIndexSqlDefinition($index)
542+
);
543+
544+
$instructions->addAlter($alter);
545+
}
546+
547+
return $instructions;
532548
}
533549

534550
/**

tests/Phinx/Db/Adapter/MysqlAdapterTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -851,6 +851,27 @@ public function testAddIndex()
851851
$this->assertTrue($table->hasIndex('email'));
852852
}
853853

854+
public function testAddMultipleFulltextIndex()
855+
{
856+
$table = new \Phinx\Db\Table('table1', [], $this->adapter);
857+
$table->addColumn('email', 'string')
858+
->addColumn('username', 'string')
859+
->addColumn('bio', 'text')
860+
->save();
861+
$this->assertFalse($table->hasIndex('email'));
862+
$this->assertFalse($table->hasIndex('username'));
863+
$this->assertFalse($table->hasIndex('address'));
864+
$table->addIndex('email')
865+
->addIndex('username', ['type' => 'fulltext'])
866+
->addIndex('bio', ['type' => 'fulltext'])
867+
->addIndex(['email', 'bio'], ['type' => 'fulltext'])
868+
->save();
869+
$this->assertTrue($table->hasIndex('email'));
870+
$this->assertTrue($table->hasIndex('username'));
871+
$this->assertTrue($table->hasIndex('bio'));
872+
$this->assertTrue($table->hasIndex(['email', 'bio']));
873+
}
874+
854875
public function testAddIndexWithLimit()
855876
{
856877
$table = new \Phinx\Db\Table('table1', [], $this->adapter);

0 commit comments

Comments
 (0)