54 lines
1.5 KiB
PHP
54 lines
1.5 KiB
PHP
<?php
|
|
/**
|
|
* run_005_registro_exams.php
|
|
* Ejecuta la migración 005 — tablas de Registro de Exámenes.
|
|
*
|
|
* USO: php run_005_registro_exams.php (o abrirlo en el navegador si el servidor lo permite)
|
|
*/
|
|
|
|
require_once __DIR__ . '/config/config.php';
|
|
|
|
header('Content-Type: text/plain; charset=utf-8');
|
|
|
|
$sqlFile = __DIR__ . '/migrations/005_registro_exams.sql';
|
|
|
|
if (!file_exists($sqlFile)) {
|
|
die("ERROR: No se encontró {$sqlFile}\n");
|
|
}
|
|
|
|
$sql = file_get_contents($sqlFile);
|
|
|
|
// Filtrar comentarios de línea y dividir en sentencias
|
|
$statements = array_filter(
|
|
array_map('trim', explode(';', $sql)),
|
|
fn($s) => $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";
|