migrations
migrations copied to clipboard
Doctrine Migrations Repeatedly Generates Same Migration for Unique Constraint with Where Condition
Bug Report
| Q | A |
|---|---|
| BC Break | yes/no |
| Version | 3.8.2 |
| Database | postgresql 16 |
Summary
The issue involves Doctrine migrations generating the same migration repeatedly, even when the schema hasn't changed. This occurs when adding a unique constraint with a where condition to an entity.
Current behavior
The doctrine:migrations:diff command generates the same migration repeatedly, even when the schema hasn't changed.
final class Version20250324153617 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('DROP INDEX UNIQ_523E1DC0F1FAD9D3296CD8AE3952D0CB');
$this->addSql('CREATE UNIQUE INDEX UNIQ_523E1DC0F1FAD9D3296CD8AE3952D0CB ON app_bundle_ids (bundle_id, team_id, platform) WHERE deleted IS NULL');
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('DROP INDEX uniq_523e1dc0f1fad9d3296cd8ae3952d0cb');
$this->addSql('CREATE UNIQUE INDEX uniq_523e1dc0f1fad9d3296cd8ae3952d0cb ON app_bundle_ids (bundle_id, team_id, platform) WHERE (deleted IS NULL)');
}
}
How to reproduce
- Add the following annotation to an entity:
#[ORM\UniqueConstraint(columns: ['bundle_id', 'team_id', 'platform'], options: ['where' => 'deleted IS NULL'])] - Run the
bin/console doctrine:migrations:diffcommand. - Run the
bin/console doctrine:migrations:migratecommand. - Run the
bin/console doctrine:migrations:diffcommand. - Observe that the same migration is generated repeatedly.
Expected Behavior
The doctrine:migrations:diff command should not generate a migration if the schema is already in sync with the mapping information.