tourze / doctrine-indexed-bundle
Doctrine索引增强
Installs: 3 796
Dependents: 20
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: ^8.1
- doctrine/doctrine-bundle: ^2.13
- doctrine/orm: ^2.20 || ^3.0
- doctrine/persistence: ^3.1 || ^4
- symfony/config: ^6.4
- symfony/dependency-injection: ^6.4
- symfony/framework-bundle: ^6.4
- symfony/http-kernel: ^6.4
- symfony/yaml: ^6.4 || ^7.1
- yiisoft/strings: ^2.1
Requires (Dev)
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^10.0
This package is auto-updated.
Last update: 2025-04-27 10:00:49 UTC
README
A Symfony bundle that enhances Doctrine ORM with automatic index management.
Features
- Automatically adds indexes to specified entity properties
- Supports regular, fulltext, and unique indexes
- Smart index naming strategy, automatically handles long table names
- Attribute-based configuration (PHP 8 attributes), no extra config files
- Zero configuration required, works out-of-the-box
Requirements
- PHP 8.1 or higher
- Symfony 6.4 or higher
- Doctrine Bundle 2.13 or higher
Installation
composer require tourze/doctrine-indexed-bundle
Usage
- Register the bundle in
config/bundles.php
:
return [ // ... Tourze\DoctrineIndexedBundle\DoctrineIndexedBundle::class => ['all' => true], ];
- Use attributes to mark entity fields that require indexes:
use Tourze\DoctrineIndexedBundle\Attribute\IndexColumn; use Tourze\DoctrineIndexedBundle\Attribute\FulltextColumn; use Tourze\DoctrineIndexedBundle\Attribute\UniqueColumn; class YourEntity { #[ORM\Column] #[IndexColumn] // Regular index private string $name; #[ORM\Column(type: 'text')] #[FulltextColumn] // Fulltext index private string $description; #[ORM\Column] #[UniqueColumn] // Unique index private string $email; }
Index Naming Convention
The bundle automatically generates index names as follows:
- Regular index:
{table_name}_idx_{column_name}
- Fulltext index:
{table_name}_fulltext_{column_name}
- Unique index:
{table_name}_unique_{column_name}
If the generated name exceeds the maximum length (64 characters), the bundle will use MD5 hashing to create a shorter name while maintaining uniqueness.
How It Works
- Listens to Doctrine's
loadClassMetadata
event and scans entity properties. - Checks for
IndexColumn
,FulltextColumn
, orUniqueColumn
attributes on properties. - Automatically adds the corresponding index to the entity field.
- Naming strategy ensures compatibility with DBMS index name length limits.
Contributing
Feel free to submit issues and pull requests to help improve this bundle.
License
MIT License