You can create database indexes using #[ORM\Index(fields: ['fieldName'] attribute on the entity file and Doctrine will do the rest to manage the index for you, but I will not talk about that.
As your project grows or requires specific requirements, you may need to use custom index types like GIST, GIN, BRIN, etc (https://www.postgresql.org/docs/current/indexes-types.html). Doctrine does not support creating database-vendor-specific index types out-of-the-box (ref).
To tackle this issue you can either execute the CREATE INDEX DDL directly to the database or write the DDL on doctrine-migrations file. The latter option gives you the benefit of easier to deploy or rollback the changes.
No matter which method you use to create the custom index, Doctrine will always mark those custom indexes as unmapped indexes hence if you execute doctrine:schema:validate you will get an error that state if your database is not in sync, the same while executing doctrine:schema:update --dump-sql or doctrine:migrations:diff it will show you DROP INDEX ... statement to remove the custom indexes.
I'm using these package versions. (I believe the solution will work on the same major version of the packages):
I found several tutorials to handle this but it is not satisfying:
I found a GitHub issue about platform_service config replacement here https://github.com/doctrine/DoctrineBundle/issues/1656.
Reading these 2 pages gave me all the pieces of information on how to use a custom DBAL platform through Doctrine middleware:
Finally, after digging into the source code, I found the solution. You need to create 4 files, 2 files are about Doctrine middleware and 2 other files are about Doctrine DBAL platform and schema.
Modify the namespace and class name as your needs.
true, 'index_name_2' => true, ]; #[\Override] protected function _getPortableTableIndexesList(array $tableIndexes, string $tableName): array { $indexes = parent::_getPortableTableIndexesList($tableIndexes, $tableName); foreach (array_keys($indexes) as $indexName) { if (isset(self::IGNORED_INDEXES[$indexName])) { unset($indexes[$indexName]); } } return $indexes; } }
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3