<?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\Main;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

final class Version20250617141354 extends AbstractMigration
{
    public function getDescription(): string
    {
        return 'When a row in chill_main_saved_export is deleted, set the references to NULL in chill_main_export_generation table';
    }

    public function up(Schema $schema): void
    {
        $this->addSql(<<<'SQL'
            ALTER TABLE chill_main_export_generation DROP CONSTRAINT FK_E644B77DA61D6F69
        SQL);
        $this->addSql(<<<'SQL'
            ALTER TABLE chill_main_export_generation ADD CONSTRAINT FK_E644B77DA61D6F69 FOREIGN KEY (savedExport_id) REFERENCES chill_main_saved_export (id) ON DELETE SET NULL NOT DEFERRABLE INITIALLY IMMEDIATE
        SQL);
    }

    public function down(Schema $schema): void
    {
        $this->addSql(<<<'SQL'
            ALTER TABLE chill_main_export_generation DROP CONSTRAINT fk_e644b77da61d6f69
        SQL);
        $this->addSql(<<<'SQL'
            ALTER TABLE chill_main_export_generation ADD CONSTRAINT fk_e644b77da61d6f69 FOREIGN KEY (savedexport_id) REFERENCES chill_main_saved_export (id) NOT DEFERRABLE INITIALLY IMMEDIATE
        SQL);
    }
}
