Symfony2 / Doctrine2: Don't drop fulltext index on schema:update
I was able to solve this using migrations then adding fake indices with the same name.
A migration added the actual fulltext index using raw SQL:
$this->addSql('ALTER TABLE content ADD FULLTEXT fulltext_content(title, description)');
Then I added the index to the Entity definition:
@ORM\Table(name="content", indexes={@ORM\Index(name="fulltext_content",columns={"title","description"})})
As long as you generate the fulltext indices first, Doctrine will no longer delete them.
Like someone else answered it's not a good idea to use doctrine:schema:update
on production because any minor error in your code could potentially cause half your database to be dropped.
I work on a fairly large project and we use doctrine:schema:update --dump-sql
to find queries that need to be executed and execute them manually.
Edit: The only other suggestion I have in addition is if you don't want to execute queries manually you could process the output of doctrine:schema:update --dump-sql
filter the queries you don't want to execute and run the remaining ones on the database. Or create a command that creates your indexes after updating your schema, something like myproject:schema:createIndexes
(or whatever)
- You shouldn't use doctrine:schema:update on production. Use migrations instead.
- As I remember Doctrine 2 doesn't have MyIsam full support, but you can create table manually and use it
- Mysql Fulltext search is not the best choise for searching. Maybe Sphinx or Lucene are more appropriate solution for your task?