diff --git a/create_scheduled_table.php b/create_scheduled_table.php new file mode 100644 index 0000000..b3463b7 --- /dev/null +++ b/create_scheduled_table.php @@ -0,0 +1,47 @@ +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"; +} diff --git a/fix_migration_v2.php b/fix_migration_v2.php new file mode 100644 index 0000000..495fa88 --- /dev/null +++ b/fix_migration_v2.php @@ -0,0 +1,56 @@ + $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"; +}