Files
whatsapp/run_migration_consentimientos_datos.php
T
2026-06-16 16:35:12 -05:00

53 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_turnero_consentimientos_datos
* Agrega columna datos_respuestas a turnero_consentimientos.
* Ejecutar una sola vez desde el navegador o CLI.
*/
require_once __DIR__ . '/config/config.php';
$sqlFile = __DIR__ . '/migrations/20260616_turnero_consentimientos_datos.sql';
if (!file_exists($sqlFile)) {
die("❌ Archivo no encontrado: $sqlFile\n");
}
try {
$pdo = Database::getInstance()->getConnection();
$sql = file_get_contents($sqlFile);
$statements = array_filter(array_map('trim', explode(';', $sql)));
echo "<pre>🚀 Ejecutando migración: 20260616_turnero_consentimientos_datos\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();
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 " Columna agregada a <strong>turnero_consentimientos</strong>:\n";
echo " • datos_respuestas (MEDIUMTEXT, JSON con campos llenados al firmar presencialmente)\n</pre>";
$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>";
}