algolia / algolia/search-bundle

[Bug] Aggregation will constantly show up in new Doctrine Migrations

Open
#361 3 comments 1 reaction 0 assignees View on GitHub
Dominant language
PHP
Stars
193
Forks
74
PR merge metrics
No merged PRs in 30d

Description

- Symfony version: 5.3
- Algolia Search Bundle version: 5.1.0
- Algolia Client Version: 3.0.2
- Language Version: PHP 7.4

### Description

I could reproduce this issue in multiple projects now.

Creating a new Aggregation strictly following the tutorial at https://www.algolia.com/doc/framework-integration/symfony/advanced-use-cases/multiple-models-in-one-index/?client=php will work like a charm.

However, the only thing now is that when you're using `doctrine/migrations` v3.1.4 (and possibly older versions too - I couldn't test that yet) will cause that when you run `php bin/console doctrine:migrations:diff -n` that it'll create a new migration **with the same SQL** every single time.

The SQL in question is

```php
$this->addSql('ALTER TABLE aggregation_table_name CHANGE object_id object_id VARCHAR(255) NOT NULL');
```

While my Aggregation looks like this:

```php
/**
* @ORM\Entity()
*/
class EntityAEntityBAggregation extends Aggregator implements AlgoliaIndexedEntity
{
public function getEntity () : AdvisorEntry
{
/** @var EntityA|EntityB $entity */
$entity = $this->entity;

return $entity;
}

/**
* @inheritdoc
*/
public static function getEntities () : array
{
return [
EntityA::class,
EntityB::class,
];
}

/**
* @inheritdoc
*/
public function getId () : ?int
{
/** @var AlgoliaIndexedEntity $entity */
$entity = $this->entity;

return $entity->getId();
}

/**
* @inheritdoc
*/
public function isIndexed () : bool
{
/** @var AlgoliaIndexedEntity $entity */
$entity = $this->entity;

return $entity->isIndexed();
}
}
```

### Steps To Reproduce

- Create a new aggregation using the tutorial at https://www.algolia.com/doc/framework-integration/symfony/advanced-use-cases/multiple-models-in-one-index/?client=php
- Install `doctrine/migrations` using `composer require doctrine/migrations`
- Create your first migration using `php bin/console doctrine:migrations:diff -n`
- Execute your first migration using `php bin/console doctrine:migrations:migrate -n`
- Try re-creating a migration without making any changes to your entities using `php bin/console doctrine:migrations:diff -n`
- Find your new migration with an update only to your aggregation's id field, which applies exactly the same changes as in your previous migration.

Contributor guide

Open the contributing guide

Research direction

Start with the aggregation entity shown in the issue and the Doctrine migration commands in the reproduction steps. Run doctrine:migrations:diff -n twice without changing the entities, then compare the generated SQL, especially the repeated object_id alteration. Done means repeated diffs produce no migration after the initial migration is applied.

Written by the indexing model from the issue text.

Assessment

Tech stack
php, symfony
Domain
backend, database
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.