Skip to content

Commit

Permalink
Add docs for new 1.0 version
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikolay Parshakov authored and underground20 committed Aug 26, 2024
1 parent a536fe8 commit 3b663e7
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
composer.lock
composer.phar
vendor/*
/vendor

# Other
.DS_Store
Expand Down
62 changes: 60 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# CustomIndexBundle

The CustomIndexBundle allows create index for doctrine entities using annotation with entity definition and console command.
The CustomIndexBundle allows create index for doctrine entities using annotation/attribute with entity definition and console command.

## Installation

CustomIndexBundle requires Symfony 2.1 or higher. Now work only with PostgreSQL.
CustomIndexBundle requires Symfony 5 or higher. Work only with PostgreSQL.

Run into your project directory:
```
Expand Down Expand Up @@ -116,3 +116,61 @@ Create partial index:
```
@CustomIndexAnnotation\CustomIndex(columns={"site_id"}, where="product_id IS NULL")
```

## New v1.0 version package

### Major changes:
<ul>
<li>Minimum php version raised to 8.1</li>
<li>Removed support for symfony < 5</li>
<li>Now you must always pass an array in a property `columns` (previously it was possible to pass a string/array)</li>
<li>Replaced the use of annotations with attributes</li>
</ul>

### Example using attributes

```php
<?php

namespace Acme\MyBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Intaro\CustomIndexBundle\Metadata\Attribute\CustomIndex;

#[ORM\Table(name:'my_entity')]
#[ORM\Entity]
#[CustomIndex(columns: ['my_property1'])]
#[CustomIndex(columns: ['lower(my_property1)', 'lower(my_property2)'])]
class MyEntity
{
#[ORM\Column(type:'string', length: 256)]
private $myProperty1;
#[ORM\Column(type:'string', length: 256)]
private $myProperty2;
}
```

### Automatic transition with Rector

You may use rector to automatically convert your code to the new version.

```php
<?php

use Intaro\CustomIndexBundle\Annotations\CustomIndexes;
use Intaro\CustomIndexBundle\Metadata\Attribute\CustomIndex;
use Rector\Config\RectorConfig;
use Rector\Php80\Rector\Property\NestedAnnotationToAttributeRector;
use Rector\Php80\ValueObject\AnnotationPropertyToAttributeClass;
use Rector\Php80\ValueObject\NestedAnnotationToAttribute;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->paths(['src']);

$rectorConfig->ruleWithConfiguration(NestedAnnotationToAttributeRector::class, [
new NestedAnnotationToAttribute(CustomIndexes::class, [
new AnnotationPropertyToAttributeClass(CustomIndex::class, 'indexes'),
], true),
]);
};
```
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "intaro/custom-index-bundle",
"description": "Annotation and command for control entity custom indexes",
"keywords": ["symfony2", "index", "postgresql-index"],
"keywords": ["symfony", "index", "postgresql-index"],
"type": "symfony-bundle",
"license": "MIT",
"authors": [{
Expand Down

0 comments on commit 3b663e7

Please sign in to comment.