Entity name : unique

master
Julien Rosset 2 months ago
parent 21c7a0c317
commit c2da5f7aaf

@ -0,0 +1,53 @@
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20250530165852 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(<<<'SQL'
CREATE UNIQUE INDEX UNIQ_1505DF845E237E06 ON machine (name)
SQL);
$this->addSql(<<<'SQL'
CREATE UNIQUE INDEX UNIQ_7CBE75955E237E06 ON material (name)
SQL);
$this->addSql(<<<'SQL'
CREATE UNIQUE INDEX UNIQ_D8B63A1C5E237E06 ON material_type (name)
SQL);
$this->addSql(<<<'SQL'
CREATE UNIQUE INDEX UNIQ_DA88B1375E237E06 ON recipe (name)
SQL);
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql(<<<'SQL'
DROP INDEX UNIQ_1505DF845E237E06 ON machine
SQL);
$this->addSql(<<<'SQL'
DROP INDEX UNIQ_7CBE75955E237E06 ON material
SQL);
$this->addSql(<<<'SQL'
DROP INDEX UNIQ_D8B63A1C5E237E06 ON material_type
SQL);
$this->addSql(<<<'SQL'
DROP INDEX UNIQ_DA88B1375E237E06 ON recipe
SQL);
}
}

@ -12,8 +12,9 @@ trait TNamedEntity {
/**
* @var string|null The name
*/
#[ORM\Column(length: 50)]
#[Assert\NotBlank(message: 'Veuillez saisir un email')]
#[ORM\Column(length: 50, unique: true)]
#[Assert\NotBlank(message: 'Veuillez saisir un nom')]
#[Assert\Unique(message: 'Il existe déjà un élément avec ce nom')]
private ?string $name = null;
/**

Loading…
Cancel
Save