up
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
require_once '/var/www/html/config/config.php';
|
||||
$db = Database::getInstance();
|
||||
|
||||
echo "🔄 Creando tabla scheduled_messages...\n\n";
|
||||
|
||||
try {
|
||||
$db->execute("
|
||||
CREATE TABLE IF NOT EXISTS scheduled_messages (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
user_id INT NOT NULL,
|
||||
template_id INT NULL,
|
||||
template_name VARCHAR(100) NULL,
|
||||
template_language VARCHAR(10) DEFAULT 'es',
|
||||
template_parameters JSON NULL COMMENT 'Parámetros para las variables de la plantilla',
|
||||
message_type ENUM('text', 'template') DEFAULT 'template',
|
||||
message_content TEXT NULL COMMENT 'Contenido del mensaje si es tipo text',
|
||||
scheduled_date DATE NOT NULL,
|
||||
scheduled_time TIME NOT NULL,
|
||||
status ENUM('pending', 'sent', 'failed', 'cancelled') DEFAULT 'pending',
|
||||
sent_at DATETIME NULL,
|
||||
error_message TEXT NULL,
|
||||
created_by INT NULL COMMENT 'ID del admin que creó el recordatorio',
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
|
||||
INDEX idx_user_id (user_id),
|
||||
INDEX idx_scheduled_date (scheduled_date),
|
||||
INDEX idx_status (status),
|
||||
INDEX idx_scheduled_datetime (scheduled_date, scheduled_time, status)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
|
||||
");
|
||||
echo "✅ Tabla scheduled_messages creada\n\n";
|
||||
} catch (Exception $e) {
|
||||
echo "❌ Error: " . $e->getMessage() . "\n\n";
|
||||
}
|
||||
|
||||
echo "📋 Verificando tabla:\n";
|
||||
try {
|
||||
$cols = $db->fetchAll('DESCRIBE scheduled_messages');
|
||||
echo "✅ Tabla scheduled_messages existe con " . count($cols) . " columnas:\n";
|
||||
foreach($cols as $c) {
|
||||
echo " - {$c['Field']} ({$c['Type']})\n";
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
echo "❌ Tabla NO existe: " . $e->getMessage() . "\n";
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/config/config.php';
|
||||
|
||||
$db = Database::getInstance();
|
||||
|
||||
echo "🔄 Leyendo archivo de migración...\n";
|
||||
$sqlFile = __DIR__ . '/database/02_add_template_components.sql';
|
||||
$sql = file_get_contents($sqlFile);
|
||||
|
||||
echo "Tamaño del archivo: " . strlen($sql) . " bytes\n\n";
|
||||
|
||||
// Dividir por punto y coma, pero preservando las líneas
|
||||
$lines = explode("\n", $sql);
|
||||
$currentStatement = '';
|
||||
$statements = [];
|
||||
|
||||
foreach ($lines as $line) {
|
||||
$line = trim($line);
|
||||
|
||||
// Saltar comentarios y líneas vacías
|
||||
if (empty($line) || strpos($line, '--') === 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$currentStatement .= $line . ' ';
|
||||
|
||||
// Si termina en punto y coma, es el final de la sentencia
|
||||
if (substr(trim($line), -1) === ';') {
|
||||
$statements[] = trim($currentStatement);
|
||||
$currentStatement = '';
|
||||
}
|
||||
}
|
||||
|
||||
echo "📊 Sentencias encontradas: " . count($statements) . "\n\n";
|
||||
|
||||
$count = 0;
|
||||
foreach ($statements as $i => $stmt) {
|
||||
echo "Ejecutando sentencia " . ($i + 1) . "...\n";
|
||||
echo "Preview: " . substr($stmt, 0, 100) . "...\n";
|
||||
|
||||
try {
|
||||
$db->execute($stmt);
|
||||
$count++;
|
||||
echo " ✓ OK\n\n";
|
||||
} catch (Exception $e) {
|
||||
echo " ✗ Error: " . $e->getMessage() . "\n\n";
|
||||
}
|
||||
}
|
||||
|
||||
echo "✅ Total ejecutadas exitosamente: $count\n\n";
|
||||
|
||||
echo "📋 Columnas actuales de message_templates:\n";
|
||||
$cols = $db->fetchAll('DESCRIBE message_templates');
|
||||
foreach($cols as $c) {
|
||||
echo " - {$c['Field']} ({$c['Type']})\n";
|
||||
}
|
||||
Reference in New Issue
Block a user