migrations/Version20251024120000.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.  * Fügt 'searchwords' Feld zur Course-Tabelle hinzu für erweiterte Suchfunktionalität
  8.  */
  9. final class Version20251024120000 extends AbstractMigration
  10. {
  11.     public function getDescription(): string
  12.     {
  13.         return 'Adds searchwords field to course table for enhanced search functionality';
  14.     }
  15.     public function up(Schema $schema): void
  16.     {
  17.         // Prüfe, ob Spalte bereits existiert
  18.         $this->addSql("
  19.             SET @col_exists = (
  20.                 SELECT COUNT(*) 
  21.                 FROM INFORMATION_SCHEMA.COLUMNS 
  22.                 WHERE TABLE_SCHEMA = DATABASE() 
  23.                 AND TABLE_NAME = 'course' 
  24.                 AND COLUMN_NAME = 'searchwords'
  25.             );
  26.         ");
  27.         
  28.         // Füge Spalte nur hinzu, wenn sie noch nicht existiert
  29.         $this->addSql("
  30.             SET @sql = IF(@col_exists = 0, 
  31.                 'ALTER TABLE course ADD searchwords LONGTEXT DEFAULT NULL AFTER description', 
  32.                 'SELECT 1'
  33.             );
  34.             PREPARE stmt FROM @sql;
  35.             EXECUTE stmt;
  36.             DEALLOCATE PREPARE stmt;
  37.         ");
  38.     }
  39.     public function down(Schema $schema): void
  40.     {
  41.         // Entferne Spalte nur, wenn sie existiert
  42.         $this->addSql("
  43.             SET @col_exists = (
  44.                 SELECT COUNT(*) 
  45.                 FROM INFORMATION_SCHEMA.COLUMNS 
  46.                 WHERE TABLE_SCHEMA = DATABASE() 
  47.                 AND TABLE_NAME = 'course' 
  48.                 AND COLUMN_NAME = 'searchwords'
  49.             );
  50.         ");
  51.         
  52.         $this->addSql("
  53.             SET @sql = IF(@col_exists > 0, 
  54.                 'ALTER TABLE course DROP COLUMN searchwords', 
  55.                 'SELECT 1'
  56.             );
  57.             PREPARE stmt FROM @sql;
  58.             EXECUTE stmt;
  59.             DEALLOCATE PREPARE stmt;
  60.         ");
  61.     }
  62. }