<?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);
    }
}
