migrations/Version20250416132502.php line 1

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace DoctrineMigrations;
  4. use Doctrine\DBAL\Schema\Schema;
  5. use Doctrine\Migrations\AbstractMigration;
  6. /**
  7.  * Auto-generated Migration: Please modify to your needs!
  8.  */
  9. final class Version20250416132502 extends AbstractMigration
  10. {
  11.     public function getDescription(): string
  12.     {
  13.         return 'Vérification et suppression sécurisée de la clé étrangère FK_ADCFE0FAC3A0A4F8';
  14.     }
  15.     public function up(Schema $schema): void
  16.     {
  17.         // Vérifier si la clé étrangère existe avant de la supprimer
  18.         $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\')');
  19.         $this->addSql('SET @sql = IF(@constraint_name IS NOT NULL, \'ALTER TABLE user DROP FOREIGN KEY FK_ADCFE0FAC3A0A4F8\', \'SELECT 1\')');
  20.         $this->addSql('PREPARE stmt FROM @sql');
  21.         $this->addSql('EXECUTE stmt');
  22.         $this->addSql('DEALLOCATE PREPARE stmt');
  23.     }
  24.     public function down(Schema $schema): void
  25.     {
  26.         // Ne rien faire dans le down car nous ne voulons pas recréer la clé étrangère
  27.     }
  28. }