doctrine / migrations

Doctrine Database Migrations Library
https://www.doctrine-project.org/projects/migrations.html
MIT License
4.65k stars 386 forks source link

Doctrine migrations tries to change the order of composite keys #1366

Open khrizt opened 9 months ago

khrizt commented 9 months ago

Bug Report

Q A
BC Break no
Version 3.5.2

Summary

Bug report about a changing the primary key order of a composite primary key when generating new migrations.

Current behavior

Each time I create a migration the same SQL statements appear trying to change the order of a composite primary key.

How to reproduce

Create an entity with the following mapping:

<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
                      https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">

  <entity name="Entities\ModuleText" table="module_texts">
    <id name="module" association-key="true" />
    <id name="locale" type="string" />
    <many-to-one field="module" target-entity="Entities\Module" inversed-by="texts">
      <join-column name="module_id" referenced-column-name="id" nullable="false" />
    </many-to-one>
    <field name="name" type="string" nullable="false" />
    <field name="description" type="string" nullable="false" />
    <field name="instructions" type="text" nullable="false" />
  </entity>
</doctrine-mapping>

Every time doctrine-migrations migrations:diff is executed the following code is generated:

$this->addSql('DROP INDEX "primary"');
$this->addSql('ALTER TABLE module_texts ADD PRIMARY KEY (locale, module_id)');

Tries to drop the primary key and create a new one switching the field order.

Expected behavior

The expected behavior would be not creating this SQL statements.

khrizt commented 9 months ago

Looks like a bug issue in Doctrine has already been opened: https://github.com/doctrine/orm/issues/9171