<?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 Version20250416132502 extends AbstractMigration
{
public function getDescription(): string
{
return 'Vérification et suppression sécurisée de la clé étrangère FK_ADCFE0FAC3A0A4F8';
}
public function up(Schema $schema): void
{
// Vérifier si la clé étrangère existe avant de la supprimer
$this->addSql('SET @constraint_name = (SELECT CONSTRAINT_NAME FROM information_schema.TABLE_CONSTRAINTS WHERE CONSTRAINT_SCHEMA = DATABASE() AND CONSTRAINT_TYPE = \'FOREIGN KEY\' AND CONSTRAINT_NAME = \'FK_ADCFE0FAC3A0A4F8\')');
$this->addSql('SET @sql = IF(@constraint_name IS NOT NULL, \'ALTER TABLE user DROP FOREIGN KEY FK_ADCFE0FAC3A0A4F8\', \'SELECT 1\')');
$this->addSql('PREPARE stmt FROM @sql');
$this->addSql('EXECUTE stmt');
$this->addSql('DEALLOCATE PREPARE stmt');
}
public function down(Schema $schema): void
{
// Ne rien faire dans le down car nous ne voulons pas recréer la clé étrangère
}
}