DDC-3671: Duplicated unique indexes (@UniqueConstraint annotation) #4507

Closed
opened 2026-01-22 14:43:22 +01:00 by admin · 3 comments
Owner

Originally created by @doctrinebot on GitHub (Apr 7, 2015).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user webimpress:

In this commit:
fc8beca086
was changed to not checking for if index already exists. After that occur problem with duplicated unique keys (for example migrations try add unique index on the same columns with different index name).

This is an example model:

/****
 * @Entity
 * @Table(name="double*uniq_index*table", uniqueConstraints={
 *   @UniqueConstraint(name="uniq_hash", columns={"hash"})
 * })
 */
class DoubleUniqIndexModel
{
    /*** @Id @Column **/
    private $id;

    /*** @Column(name="hash", type="string", length=8, nullable=false, unique=true) **/
    private $hash;
}

and the basic test:

    public function testDoubleUniqIndex()
    {
        $em = $this->_getTestEntityManager();
        $schemaTool = new SchemaTool($em);

        $classes = array(
            $em->getClassMetadata(*_NAMESPACE_* . '\\DoubleUniqIndexModel'),
        );

        $schema = $schemaTool->getSchemaFromMetadata($classes);

        $this->assertTrue($schema->hasTable('double*uniq_index*table'));
        $this->assertEquals(2, count($schema->getTable('double*uniq_index*table')->getIndexes()));
    }

(I've added it into: tests/Doctrine/Tests/ORM/Tools/SchemaToolTest.php).

Test failures, because generated schema contains three indexes (primary, and two unique on the same column with different names - one auto generated uniq** and one provided in annotations - uniq*hash).

Originally created by @doctrinebot on GitHub (Apr 7, 2015). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user webimpress: In this commit: https://github.com/doctrine/dbal/commit/fc8beca08600b44e46f7b82998adbcc6d52c31f1 was changed to not checking for if index already exists. After that occur problem with duplicated unique keys (for example migrations try add unique index on the same columns with different index name). This is an example model: ``` /**** * @Entity * @Table(name="double*uniq_index*table", uniqueConstraints={ * @UniqueConstraint(name="uniq_hash", columns={"hash"}) * }) */ class DoubleUniqIndexModel { /*** @Id @Column **/ private $id; /*** @Column(name="hash", type="string", length=8, nullable=false, unique=true) **/ private $hash; } ``` and the basic test: ``` public function testDoubleUniqIndex() { $em = $this->_getTestEntityManager(); $schemaTool = new SchemaTool($em); $classes = array( $em->getClassMetadata(*_NAMESPACE_* . '\\DoubleUniqIndexModel'), ); $schema = $schemaTool->getSchemaFromMetadata($classes); $this->assertTrue($schema->hasTable('double*uniq_index*table')); $this->assertEquals(2, count($schema->getTable('double*uniq_index*table')->getIndexes())); } ``` (I've added it into: `tests/Doctrine/Tests/ORM/Tools/SchemaToolTest.php`). Test failures, because generated schema contains three indexes (primary, and two unique on the same column with different names - one auto generated `uniq**` and one provided in annotations - `uniq*hash`).
admin added the Bug label 2026-01-22 14:43:22 +01:00
admin closed this issue 2026-01-22 14:43:23 +01:00
Author
Owner

@doctrinebot commented on GitHub (Apr 7, 2015):

@doctrinebot commented on GitHub (Apr 7, 2015): - is duplicated by [DDC-3677: [GH-1375] DDC-3671 prevent duplicate unique index](http://www.doctrine-project.org/jira/browse/DDC-3677)
Author
Owner

@zerocrates commented on GitHub (Dec 10, 2015):

This looks like it was closed by the merge of #4508

@zerocrates commented on GitHub (Dec 10, 2015): This looks like it was closed by the merge of #4508
Author
Owner

@Ocramius commented on GitHub (Dec 11, 2015):

@zerocrates thanks, closing!

@Ocramius commented on GitHub (Dec 11, 2015): @zerocrates thanks, closing!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#4507