$s !== '' && !preg_match('/^\s*--/', $s) ); $pdo = Database::getInstance()->getConnection(); $ok = 0; $err = 0; foreach ($statements as $stmt) { $stmt = trim($stmt); if ($stmt === '') { continue; } try { $pdo->exec($stmt); echo "OK: " . substr(preg_replace('/\s+/', ' ', $stmt), 0, 80) . "\n"; $ok++; } catch (PDOException $e) { $msg = $e->getMessage(); // Ignorar errores de "ya existe" (idempotente) if (str_contains($msg, 'already exists') || str_contains($msg, 'Duplicate entry')) { echo "SKIP (ya existe): " . substr($stmt, 0, 60) . "\n"; } else { echo "ERROR: {$msg}\n >> " . substr($stmt, 0, 100) . "\n"; $err++; } } } echo "\n─────────────────────────────────\n"; echo "Migración 005 completada. OK={$ok} ERRORES={$err}\n";