Files
whatsapp/run_migration_firma_profesional_turnero.php
T
2026-06-16 12:06:26 -05:00

56 lines
1.8 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
/**
* Runner — Migración 20260616: firma_profesional en turnero_consentimientos
* Ejecutar una sola vez desde el navegador o CLI.
*/
require_once __DIR__ . '/config/config.php';
$sqlFile = __DIR__ . '/migrations/20260616_turnero_firma_profesional.sql';
if (!file_exists($sqlFile)) {
die("❌ Archivo no encontrado: $sqlFile\n");
}
try {
$pdo = Database::getInstance()->getConnection();
$sql = file_get_contents($sqlFile);
// Separar sentencias
$statements = array_filter(array_map('trim', explode(';', $sql)));
echo "<pre>🚀 Ejecutando migración: 20260616_turnero_firma_profesional\n\n";
foreach ($statements as $stmt) {
$clean = preg_replace('/--[^\n]*/', '', $stmt);
$clean = trim($clean);
if (empty($clean)) continue;
try {
$pdo->exec($clean);
$preview = substr(preg_replace('/\s+/', ' ', $clean), 0, 120);
echo "✓ {$preview}\n";
} catch (PDOException $e) {
$msg = $e->getMessage();
// Ignorar si la columna ya existe
if (str_contains($msg, 'Duplicate column') || str_contains($msg, 'errno: 1060')) {
echo "️ (columna ya existe, omitida)\n";
} else {
throw $e;
}
}
}
echo "\n✅ Migración completada.\n";
echo " Columnas agregadas a <strong>turnero_consentimientos</strong>:\n";
echo " • firma_profesional_svg\n";
echo " • firmado_profesional_at\n</pre>";
// Verificación
$cols = $pdo->query("SHOW COLUMNS FROM turnero_consentimientos")->fetchAll(PDO::FETCH_COLUMN);
echo "<pre>📋 Columnas actuales: " . implode(', ', $cols) . "</pre>";
} catch (Throwable $e) {
echo "<pre>❌ Error: " . htmlspecialchars($e->getMessage()) . "\n</pre>";
}