Skip to content

Doctrine Migrations Repeatedly Generates Same Migration for Unique Constraint with Where Condition #1497

@wietsedecnijf

Description

@wietsedecnijf

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

  1. Add the following annotation to an entity:
    #[ORM\UniqueConstraint(columns: ['bundle_id', 'team_id', 'platform'], options: ['where' => 'deleted IS NULL'])]
  2. Run the bin/console doctrine:migrations:diff command.
  3. Run the bin/console doctrine:migrations:migrate command.
  4. Run the bin/console doctrine:migrations:diff command.
  5. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions