Specify the table type/storage engine in Doctrine 2
Asked Answered
S

3

16

So how can one specify the storage engine to use for a given entity in Doctrine 2?

I'm creating a table that needs a full text index and only the MyISAM storage engine supports full text indexing in MySQL.

As a side: it looks like Doctrine 2 doesn't support full text indexing out of the box? Nor full text searches? Is that correct?

Schwann answered 23/9, 2011 at 1:1 Comment(4)
It may not be "possible" without editing source: doctrine-project.org/jira/browse/DDC-972Cp
Also (1.1): doctrine-project.org/documentation/manual/1_1/zh/…Cp
@Jared I figured as much... thanks for the ticket link.Schwann
A work-around from Benjamin Eberlei - groups.google.com/group/doctrine-user/browse_thread/thread/…Ramification
C
28

I'm two years too late, but knowing this is important since it isn't documented for some reason, we have been struggling to achieve this but this is the solution

/**
 * ReportData
 *
 * @ORM\Table(name="reports_report_data",options={"engine":"MyISAM"})
 * @ORM\Entity(repositoryClass="Jac\ReportGeneratorBundle\Entity\ReportDataRepository")
 */
class ReportData
{
Colloidal answered 21/7, 2014 at 13:53 Comment(2)
please only notice the options={"engine":"MyISAM"}Colloidal
Thanks!, don't know why this isn't marked as the answer, weird.Rivkarivkah
T
7

Update:

See the comment about adding "@Table(name="table_name",options={"engine"="MyISAM"})" , it is the better answer.

======= Original Below ===========

This is untested code aimed to help you get to an answer, you will need to read a lot of Doctrine2 code to figure out what you want though. I spent about 30mins reading code and couldnt find a way to push the $options array through the ORM layer to this DBAL layer function.

check out Doctrine/DBAL/Platforms/MySQLPlatform.php

427         // get the type of the table
428         if (isset($options['engine'])) {
429             $optionStrings[] = 'ENGINE = ' . $options['engine'];
430         } else {
431             // default to innodb
432             $optionStrings[] = 'ENGINE = InnoDB';
433         }

try hard coding what engine want in there. It will almost certainly break stuff though (eg, foreign keys dont work in MyISAM)

Thermostat answered 11/5, 2012 at 0:16 Comment(2)
You can set this for a table using @Table(name="table_name",options={"engine"="MyISAM"})Sinusitis
@PaulJacobse you should post this as an answerOperose
T
3

If you're using doctrine2 migrations ..

$table = $schema->createTable('user');
$table->addColumn('id', 'integer');
$table->addOption('engine' , 'MyISAM');
$table->setPrimaryKey(array('id'));
Tibetoburman answered 21/12, 2012 at 15:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.