Skip to content

Commit

Permalink
Merge pull request #246 from hason/fulltext_index
Browse files Browse the repository at this point in the history
Fixed sql for creating table with fulltext index
  • Loading branch information
guilhermeblanco committed Jan 8, 2013
2 parents fed3d65 + da1fe6c commit 2f3377c
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 8 deletions.
8 changes: 1 addition & 7 deletions lib/Doctrine/DBAL/Platforms/AbstractPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -1893,17 +1893,11 @@ public function getUniqueConstraintDeclarationSQL($name, Index $index)
*/
public function getIndexDeclarationSQL($name, Index $index)
{
$type = '';

if ($index->isUnique()) {
$type = 'UNIQUE ';
}

if (count($index->getColumns()) === 0) {
throw new \InvalidArgumentException("Incomplete definition. 'columns' required.");
}

return $type . 'INDEX ' . $name . ' ('
return $this->getCreateIndexSQLFlags($index) . 'INDEX ' . $name . ' ('
. $this->getIndexFieldDeclarationListSQL($index->getColumns())
. ')';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,21 @@ public function testDiffTableBug()

$this->assertFalse($diff, "no changes expected.");
}
}

public function testFulltextIndex()
{
$table = new Table('fulltext_index');
$table->addColumn('text', 'text');
$table->addIndex(array('text'), 'f_index');
$table->addOption('engine', 'MyISAM');

$index = $table->getIndex('f_index');
$index->addFlag('fulltext');

$this->_sm->dropAndCreateTable($table);

$indexes = $this->_sm->listTableIndexes('fulltext_index');
$this->assertArrayHasKey('f_index', $indexes);
$this->assertTrue($indexes['f_index']->hasFlag('fulltext'));
}
}
14 changes: 14 additions & 0 deletions tests/Doctrine/Tests/DBAL/Platforms/MySqlPlatformTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,4 +240,18 @@ protected function getQuotedColumnInIndexSQL()
'CREATE TABLE `quoted` (`key` VARCHAR(255) NOT NULL, INDEX IDX_22660D028A90ABA9 (`key`)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB'
);
}

public function testCreateTableWithFulltextIndex()
{
$table = new Table('fulltext_table');
$table->addOption('engine', 'MyISAM');
$table->addColumn('text', 'text');
$table->addIndex(array('text'), 'fulltext_text');

$index = $table->getIndex('fulltext_text');
$index->addFlag('fulltext');

$sql = $this->_platform->getCreateTableSQL($table);
$this->assertEquals(array('CREATE TABLE fulltext_table (text LONGTEXT NOT NULL, FULLTEXT INDEX fulltext_text (text)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = MyISAM'), $sql);
}
}

0 comments on commit 2f3377c

Please sign in to comment.