From 1342d305ec543119207cb93af16805d6f39871bb Mon Sep 17 00:00:00 2001 From: Lizandro Guarnizo <77708265+lizandrogd@users.noreply.github.com> Date: Tue, 23 Jun 2026 19:24:41 -0500 Subject: [PATCH] fix: corregir migraciones fallidas, redis doble carga y cache de assets MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Eliminar .env del tracking de git (credenciales no deben ir en repo) - Agregar .env y .env.* al .dockerignore (no hornear credenciales en imagen) - Quitar extension=redis.so duplicada en php.ini - Activar cache 7d para assets estáticos en nginx - Corregir 5 migraciones: eliminar INSERT INTO migrations con columna incorrecta y remover semicolons en comentarios -- que partian el parser SQL Co-Authored-By: Claude Sonnet 4.6 --- .dockerignore | 7 ++- .env | 55 ------------------- .env.docker | 50 ----------------- .gitignore | 2 + docker/nginx/default.conf | 13 +---- docker/php/php.ini | 3 +- migrations/001_rbac_expandido.sql | 3 - migrations/002_nuevos_roles.sql | 3 - migrations/003_turnero.sql | 2 +- .../20260402_formularios_readonly_write.sql | 2 +- migrations/20260416_roles_home_page.sql | 3 - 11 files changed, 12 insertions(+), 131 deletions(-) delete mode 100644 .env delete mode 100644 .env.docker diff --git a/.dockerignore b/.dockerignore index 42f3704..6a204ee 100644 --- a/.dockerignore +++ b/.dockerignore @@ -30,9 +30,10 @@ Thumbs.db .vscode/ *.sublime-* -# Variables de entorno locales -.env.local -.env.*.local +# Variables de entorno — nunca en la imagen +.env +.env.* +!.env.example # Backups backups/ diff --git a/.env b/.env deleted file mode 100644 index 315b1c5..0000000 --- a/.env +++ /dev/null @@ -1,55 +0,0 @@ -# ============================================================ -# WhatsApp Bot Manager — Variables de entorno -# Fuente única de verdad para desarrollo local. -# En producción (Coolify): configurar en Environment Variables de la app. -# ⚠️ Este archivo NO se sube a git (.gitignore lo excluye). -# ============================================================ - -# ── Base de datos ───────────────────────────────────────────── -DB_HOST=46.202.93.92 -DB_PORT=3306 -DB_NAME=usite_whatsapp_bot -DB_USER=usite_whatsapp_user -DB_PASS=6q!Vio0fn@PFmsLyHjH5 -DB_ROOT_PASSWORD=root_password_2026 -DB_CHARSET=utf8mb4 - -# ── Redis ───────────────────────────────────────────────────── -REDIS_HOST=127.0.0.1 -REDIS_PORT=6379 -REDIS_PASSWORD= - -# ── WhatsApp Business API ───────────────────────────────────── -WHATSAPP_TOKEN=EAAcGjPRqunIBQjy3mZAVLX2vfMcyfUtcAXAwul5tZCQjsdxyEljIV1C4mOfTNAOIseZCMDZCy2O5AVM6wBXZC6nEfSNxkhosevtlZCRDr8uxe4zHiiZClW88mnjj2sv2t6PAh63VtUfY5DYAands4O5E9E6L6yiugZCZCBRIFjEWEtE1WXOn6GZCy8mgKpqTD2aQvNogZDZD -WHATSAPP_PHONE_NUMBER_ID=959898150536936 -WHATSAPP_API_URL=https://graph.facebook.com/v22.0/ -WEBHOOK_VERIFY_TOKEN=XimenaCaicedo2026*+ -AUTO_APPROVE_TEMPLATES=true - -# ── Aplicación ──────────────────────────────────────────────── -APP_ENV=development -APP_DEBUG=true -APP_NAME=WhatsApp Bot System -APP_VERSION=2.0.0 -APP_URL=https://bot.u-s.app/ -TIMEZONE=America/Bogota - -# ── Logs ────────────────────────────────────────────────────── -# Valores: DEBUG | INFO | WARNING | ERROR -LOG_LEVEL=DEBUG -ENABLE_LOGGING=true -LOG_FILE=logs/system.log - -# ── Seguridad ───────────────────────────────────────────────── -SESSION_TIMEOUT=1800 -MAX_LOGIN_ATTEMPTS=3 -LOGIN_LOCKOUT_TIME=900 - -# ── Rate Limiting ───────────────────────────────────────────── -ENABLE_RATE_LIMIT=false - -# ── PHP ─────────────────────────────────────────────────────── -PHP_MEMORY_LIMIT=512M -PHP_MAX_EXECUTION_TIME=300 -DISPLAY_ERRORS=1 -ERROR_REPORTING=E_ALL diff --git a/.env.docker b/.env.docker deleted file mode 100644 index 2053f57..0000000 --- a/.env.docker +++ /dev/null @@ -1,50 +0,0 @@ -# Variables de entorno para Docker Compose -# Copia este archivo como .env y completa los valores - -# =========================================== -# APLICACIÓN -# =========================================== -APP_ENV=production -APP_PORT=8080 - -# =========================================== -# BASE DE DATOS -# =========================================== -DB_HOST=db -DB_PORT=3306 -DB_NAME=whatsapp_bot -DB_USER=whatsapp_user -DB_PASS=tu_password_seguro_aqui -DB_ROOT_PASSWORD=root_password_super_seguro - -# =========================================== -# REDIS -# =========================================== -REDIS_HOST=127.0.0.1 -REDIS_PORT=6379 -REDIS_PASSWORD= -REDIS_DB=0 - -# =========================================== -# WHATSAPP API -# =========================================== -WHATSAPP_TOKEN=tu_token_de_whatsapp_aqui -WHATSAPP_PHONE_NUMBER_ID=tu_phone_number_id_aqui -WEBHOOK_VERIFY_TOKEN=tu_token_verificacion_webhook - -# =========================================== -# LOGGING -# =========================================== -LOG_LEVEL=INFO -ENABLE_RATE_LIMIT=true - -# =========================================== -# WORKERS -# =========================================== -WORKER_REPLICAS=2 - -# =========================================== -# HERRAMIENTAS DE DESARROLLO (opcional) -# =========================================== -PHPMYADMIN_PORT=8081 -REDIS_COMMANDER_PORT=8082 diff --git a/.gitignore b/.gitignore index ee2c83a..c19e8b4 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,8 @@ # Ignorar credenciales y entornos .env +.env.* +!.env.example CREDENCIALES_BASICO.txt # Logs y temporales diff --git a/docker/nginx/default.conf b/docker/nginx/default.conf index 3ca4fca..d9a68e1 100644 --- a/docker/nginx/default.conf +++ b/docker/nginx/default.conf @@ -5,11 +5,6 @@ server { root /var/www/html; index index.php index.html; - # 🚫 CACHE DESACTIVADO GLOBALMENTE - add_header Cache-Control "no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0" always; - add_header Pragma "no-cache" always; - add_header Expires "0" always; - # Security headers add_header X-Frame-Options "SAMEORIGIN" always; add_header X-Content-Type-Options "nosniff" always; @@ -84,12 +79,10 @@ server { access_log off; } - # Static assets - SIN CACHE para desarrollo + # Static assets location ~* \.(jpg|jpeg|png|gif|ico|css|js|svg|woff|woff2|ttf|eot)$ { - # CACHE DESACTIVADO - add_header Cache-Control "no-store, no-cache, must-revalidate, max-age=0" always; - add_header Pragma "no-cache" always; - expires off; + expires 7d; + add_header Cache-Control "public, max-age=604800" always; access_log off; } diff --git a/docker/php/php.ini b/docker/php/php.ini index dd5c671..fe7b6dd 100644 --- a/docker/php/php.ini +++ b/docker/php/php.ini @@ -56,5 +56,4 @@ realpath_cache_ttl = 600 ; Output buffering output_buffering = 4096 -; Redis -extension = redis.so +; Redis extension habilitada vía docker-php-ext-enable en builder stage (conf.d/docker-php-ext-redis.ini) diff --git a/migrations/001_rbac_expandido.sql b/migrations/001_rbac_expandido.sql index e3e4cb3..11feeb1 100644 --- a/migrations/001_rbac_expandido.sql +++ b/migrations/001_rbac_expandido.sql @@ -22,6 +22,3 @@ WHERE permission = 'write' OR permission IS NULL; -- Los que tienen permission='read' solo tienen can_view = 1 (ya es el DEFAULT, no tocar) --- Registrar migración -INSERT IGNORE INTO migrations (migration, executed_at) -VALUES ('001_rbac_expandido', NOW()); diff --git a/migrations/002_nuevos_roles.sql b/migrations/002_nuevos_roles.sql index 4fb4b9d..d0ab859 100644 --- a/migrations/002_nuevos_roles.sql +++ b/migrations/002_nuevos_roles.sql @@ -38,6 +38,3 @@ INSERT IGNORE INTO role_modules (role_id, module_slug, can_view, can_create, can SELECT r.id, 'whatsapp', 1, 1, 1, 0, 1 FROM roles r WHERE r.slug = 'operador_bot'; --- Registrar migración -INSERT IGNORE INTO migrations (migration, executed_at) -VALUES ('002_nuevos_roles', NOW()); diff --git a/migrations/003_turnero.sql b/migrations/003_turnero.sql index 84c1c5b..538f55e 100644 --- a/migrations/003_turnero.sql +++ b/migrations/003_turnero.sql @@ -38,7 +38,7 @@ CREATE TABLE IF NOT EXISTS exam_tipo_consentimientos ( COMMENT='M:N entre tipos de examen y formularios de consentimiento'; -- ── 3. Lugares / estaciones de servicio configurables ─────── --- Recepción NO es un lugar; es el paso implícito del flujo. +-- Recepcion NO es un lugar (es el paso implicito del flujo). -- Cada lugar tiene su propia cola y su propia pantalla TV. CREATE TABLE IF NOT EXISTS turnero_lugares ( id INT UNSIGNED NOT NULL AUTO_INCREMENT, diff --git a/migrations/20260402_formularios_readonly_write.sql b/migrations/20260402_formularios_readonly_write.sql index 3d68ead..e33cbdc 100644 --- a/migrations/20260402_formularios_readonly_write.sql +++ b/migrations/20260402_formularios_readonly_write.sql @@ -1,5 +1,5 @@ -- Rol formularios_readonly: solo acceso a lab_formularios con permiso write --- Permite crear y editar formularios; los envíos/resultados son solo lectura (UI) +-- Permite crear y editar formularios - los envios/resultados son solo lectura (UI) UPDATE role_modules SET permission = 'write' WHERE role_id = (SELECT id FROM roles WHERE slug = 'formularios_readonly') diff --git a/migrations/20260416_roles_home_page.sql b/migrations/20260416_roles_home_page.sql index eddeddc..58f2143 100644 --- a/migrations/20260416_roles_home_page.sql +++ b/migrations/20260416_roles_home_page.sql @@ -10,6 +10,3 @@ ALTER TABLE `roles` COMMENT 'Ruta de inicio al hacer login. NULL = usa reglas heredadas.' AFTER `color`; --- Registrar migración -INSERT IGNORE INTO migrations (migration, executed_at) -VALUES ('20260416_roles_home_page', NOW());