$s !== '' && $s !== "\n"
);
try {
$pdo = createDbConnection();
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$ok = 0; $errors = [];
foreach ($statements as $stmt) {
if (!trim($stmt)) continue;
try {
$pdo->exec($stmt);
$ok++;
} catch (PDOException $e) {
// Ignorar: columna ya existe, índice ya existe, clave duplicada en INSERT
$msg = $e->getMessage();
if (
str_contains($msg, 'Duplicate entry') ||
str_contains($msg, 'Duplicate key') ||
str_contains($msg, 'already exists') ||
str_contains($msg, 'Duplicate column name') ||
str_contains($msg, "Can't DROP") ||
preg_match('/already exists/i', $msg)
) {
$ok++;
} else {
$errors[] = 'Error: ' . htmlspecialchars($msg) .
'' . htmlspecialchars(substr($stmt, 0, 200)) . '';
}
}
}
?>
⚠️ Elimina o protege este archivo (run_roles_migration.php) después de ejecutarlo.