Add unique constraint for definition_id and person_id in PersonIdentifier

- Update entity to include the new database-level unique constraint.
- Add migration script to apply the unique constraint and handle rollback.
This commit is contained in:
2025-09-26 14:44:31 +02:00
parent 13b1c45271
commit ee006f55d6
2 changed files with 34 additions and 0 deletions

View File

@@ -18,6 +18,7 @@ use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity]
#[ORM\Table(name: 'chill_person_identifier')]
#[ORM\UniqueConstraint(name: 'chill_person_identifier_unique', columns: ['definition_id', 'canonical'])]
#[ORM\UniqueConstraint(name: 'chill_person_identifier_unique_person_definition', columns: ['definition_id', 'person_id'])]
#[UniqueIdentifierConstraint]
class PersonIdentifier
{

View File

@@ -0,0 +1,33 @@
<?php
declare(strict_types=1);
/*
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\Migrations\Person;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
final class Version20250926124024 extends AbstractMigration
{
public function getDescription(): string
{
return 'Add unique constraint on person_identifier: only one identifier of each kind by person';
}
public function up(Schema $schema): void
{
$this->addSql('CREATE UNIQUE INDEX chill_person_identifier_unique_person_definition ON chill_person_identifier (definition_id, person_id)');
}
public function down(Schema $schema): void
{
$this->addSql('DROP INDEX chill_person_identifier_unique_person_definition');
}
}