Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

composite unique keys are not taken in account when creating migrations #1475

Open
logosur opened this issue Dec 9, 2024 · 0 comments
Open

Comments

@logosur
Copy link

logosur commented Dec 9, 2024

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 logosur changed the title composite unique keys are not taken in account when create migration composite unique keys are not taken in account when creating migrations Dec 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant