mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-25 16:14:59 +00:00
Restrict deletion of identifier_definition
to prevent errors and ensure data integrity
- Updated foreign key constraint on `chill_person_identifier.definition_id` to use `ON DELETE RESTRICT` instead of `ON DELETE CASCADE`. - Adjusted migration script to handle both the upgrade and downgrade paths for the new restriction.
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
<?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;
|
||||
|
||||
/**
|
||||
* Restrict the deletion of identifier_definition to avoid risk of error.
|
||||
*
|
||||
* An identifier definition can only be removed if there aren't any identifier defined.
|
||||
*/
|
||||
final class Version20250924101621 extends AbstractMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'Restrict the deletion of identifier_definition';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
$this->addSql(<<<'SQL'
|
||||
ALTER TABLE chill_person_identifier DROP CONSTRAINT fk_bca5a36bd11ea911
|
||||
SQL);
|
||||
$this->addSql(<<<'SQL'
|
||||
ALTER TABLE chill_person_identifier ADD CONSTRAINT fk_bca5a36bd11ea911
|
||||
FOREIGN KEY (definition_id) REFERENCES chill_person_identifier_definition (id)
|
||||
on delete restrict
|
||||
SQL);
|
||||
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
$this->addSql(<<<'SQL'
|
||||
ALTER TABLE chill_person_identifier DROP CONSTRAINT fk_bca5a36bd11ea911
|
||||
SQL);
|
||||
$this->addSql(<<<'SQL'
|
||||
ALTER TABLE chill_person_identifier ADD CONSTRAINT fk_bca5a36bd11ea911
|
||||
FOREIGN KEY (definition_id) REFERENCES chill_person_identifier_definition (id)
|
||||
on delete cascade
|
||||
SQL);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user