migrations icon indicating copy to clipboard operation
migrations copied to clipboard

composite unique keys are not taken in account when creating migrations

Open logosur opened this issue 10 months ago • 1 comments

Bug Report

I'm trying to create a composite unique key in symfony but this is not present when migration is generated.

Q A
BC Break no
Version 2.13
Symfony version 7.2.0
Migration bundle version 3.3

Summary

Current behavior

composite key is missing in the migration file.

How to reproduce


namespace App\Entity;

use App\Repository\LinkRepository;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity(repositoryClass: LinkRepository::class)]
#[ORM\Table(name: 'link', uniqueConstraints: [
    new ORM\UniqueConstraint(name: 'unique_url_source', columns: ['source', 'url'])
])]
class Link
{
    #[ORM\Id]
    #[ORM\GeneratedValue]
    #[ORM\Column]
    private ?int $id = null;

    #[ORM\Column(options: ['default' => 0])]
    private bool $isBroken = false;

    #[ORM\Column(type: 'boolean', nullable: false)]
    private bool $internal;

    #[ORM\Column(type: 'string', length: 255, nullable: false)]
    private string $source;
    
    #[ORM\Column(type: 'text', nullable: false)]
    private string $url;

    #[ORM\Column(nullable: true)]
    private ?int $confirmations = null;

    #[ORM\Column(type: Types::DATETIME_IMMUTABLE)]
    private \DateTimeImmutable $dateDetection;

    #[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
    private ?\DateTimeInterface $dateUpdated = null;

    public function __construct()
    {
        $this->dateDetection = new \DateTimeImmutable();
    }

    public function getId(): ?int
    {
        return $this->id;
    }

    public function isBroken(): bool
    {
        return $this->isBroken;
    }

    public function setBroken(bool $isBroken): static
    {
        $this->isBroken = $isBroken;

        return $this;
    }

    public function isInternal(): bool
    {
        return $this->internal;
    }

    public function setInternal(bool $internal): static
    {
        $this->internal = $internal;

        return $this;
    }

    public function getSource(): string
    {
        return $this->source;
    }

    public function setSource(string $source): static
    {
        $this->source = $source;

        return $this;
    }

    public function getUrl(): string
    {
        return $this->url;
    }

    public function setUrl(string $url): static
    {
        $this->url = $url;

        return $this;
    }

    public function getConfirmations(): ?int
    {
        return $this->confirmations;
    }

    public function setConfirmations(?int $confirmations): static
    {
        $this->confirmations = $confirmations;

        return $this;
    }

    public function getDateDetection(): \DateTimeImmutable
    {
        return $this->dateDetection;
    }

    public function getDateUpdated(): ?\DateTimeInterface
    {
        return $this->dateUpdated;
    }

    public function setDateUpdated(?\DateTimeInterface $dateUpdated): static
    {
        $this->dateUpdated = $dateUpdated;

        return $this;
    }
}


php bin/console doctrine:migrations:diff

Expected behavior

in migration file, the following line should be present, but is not. $this->addSql('CREATE UNIQUE INDEX unique_url_source ON link (url, source)');

logosur avatar Dec 09 '24 02:12 logosur