[ 'ALTER TABLE spells ADD COLUMN IF NOT EXISTS body LONGTEXT NULL AFTER summary', ], ]; function ws_migrations_apply(PDO $pdo): void { static $applied = false; if ($applied) { return; } $applied = true; try { $pdo->exec( 'CREATE TABLE IF NOT EXISTS schema_migrations ( version INT UNSIGNED NOT NULL, applied_at DATETIME NOT NULL, PRIMARY KEY (version) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci' ); $done = array_map('intval', $pdo->query('SELECT version FROM schema_migrations')->fetchAll(PDO::FETCH_COLUMN)); foreach (WS_MIGRATIONS as $version => $statements) { if (in_array((int) $version, $done, true)) { continue; } foreach ((array) $statements as $sql) { $pdo->exec($sql); } $pdo->prepare('INSERT INTO schema_migrations (version, applied_at) VALUES (?, ?)') ->execute([(int) $version, gmdate('Y-m-d H:i:s')]); } } catch (Throwable $error) { // Migration darf die Seite nicht lahmlegen; Fehler landet im Log. error_log('Westreiche-Migration: ' . $error->getMessage()); } }