Create run_migration.php
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
/**
|
||||
* Script temporal para ejecutar migración de base de datos
|
||||
*/
|
||||
|
||||
require_once __DIR__ . '/config/config.php';
|
||||
|
||||
try {
|
||||
$db = Database::getInstance();
|
||||
$sqlFile = __DIR__ . '/database/02_add_template_components.sql';
|
||||
|
||||
if (!file_exists($sqlFile)) {
|
||||
die("❌ Archivo no encontrado: $sqlFile\n");
|
||||
}
|
||||
|
||||
$sql = file_get_contents($sqlFile);
|
||||
|
||||
// Dividir en sentencias individuales
|
||||
$statements = array_filter(array_map('trim', explode(';', $sql)));
|
||||
|
||||
echo "🚀 Ejecutando migración...\n\n";
|
||||
|
||||
foreach ($statements as $stmt) {
|
||||
// Saltar comentarios y líneas vacías
|
||||
if (empty($stmt) || preg_match('/^--/', $stmt)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
$db->execute($stmt);
|
||||
$preview = substr(preg_replace('/\s+/', ' ', $stmt), 0, 80);
|
||||
echo "✓ Ejecutado: {$preview}...\n";
|
||||
} catch (Exception $e) {
|
||||
echo "✗ Error: " . $e->getMessage() . "\n";
|
||||
echo " SQL: " . substr($stmt, 0, 100) . "...\n";
|
||||
}
|
||||
}
|
||||
|
||||
echo "\n✅ Migración completada\n\n";
|
||||
|
||||
// Verificar columnas agregadas
|
||||
echo "📋 Verificando columnas de message_templates:\n";
|
||||
$cols = $db->fetchAll('DESCRIBE message_templates');
|
||||
foreach ($cols as $col) {
|
||||
echo " - {$col['Field']} ({$col['Type']})\n";
|
||||
}
|
||||
|
||||
} catch (Exception $e) {
|
||||
echo "❌ Error fatal: " . $e->getMessage() . "\n";
|
||||
exit(1);
|
||||
}
|
||||
Reference in New Issue
Block a user