query($sql); } self::ensureColumn('replication_operations', 'progress_percent', "DECIMAL(5,2) NOT NULL DEFAULT 0.00"); self::ensureColumn('replication_operations', 'message', 'VARCHAR(512) NULL'); self::ensureColumn('replication_operations', 'context_json', 'LONGTEXT NULL'); self::$initialized = true; } private static function ensureColumn(string $table, string $column, string $definition): void { global $db; $table = preg_replace('/[^a-zA-Z0-9_]/', '', $table); $column = preg_replace('/[^a-zA-Z0-9_]/', '', $column); if ($table === '' || $column === '') { return; } $result = $db->query("SHOW COLUMNS FROM `$table` LIKE '$column'"); if ($result !== false && $result->num_rows > 0) { return; } $db->query("ALTER TABLE `$table` ADD COLUMN `$column` $definition"); } }