<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Fügt 'searchwords' Feld zur Course-Tabelle hinzu für erweiterte Suchfunktionalität
*/
final class Version20251024120000 extends AbstractMigration
{
public function getDescription(): string
{
return 'Adds searchwords field to course table for enhanced search functionality';
}
public function up(Schema $schema): void
{
// Prüfe, ob Spalte bereits existiert
$this->addSql("
SET @col_exists = (
SELECT COUNT(*)
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = DATABASE()
AND TABLE_NAME = 'course'
AND COLUMN_NAME = 'searchwords'
);
");
// Füge Spalte nur hinzu, wenn sie noch nicht existiert
$this->addSql("
SET @sql = IF(@col_exists = 0,
'ALTER TABLE course ADD searchwords LONGTEXT DEFAULT NULL AFTER description',
'SELECT 1'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
");
}
public function down(Schema $schema): void
{
// Entferne Spalte nur, wenn sie existiert
$this->addSql("
SET @col_exists = (
SELECT COUNT(*)
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = DATABASE()
AND TABLE_NAME = 'course'
AND COLUMN_NAME = 'searchwords'
);
");
$this->addSql("
SET @sql = IF(@col_exists > 0,
'ALTER TABLE course DROP COLUMN searchwords',
'SELECT 1'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
");
}
}