Fix database connection errors and schema issues
Resolve 500 errors across database API endpoints by implementing a dual-mode database driver and adding missing columns to the routers table. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 7a657272-55ba-4a79-9a2e-f1ed9bc7a528 Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Event-Id: c333ed12-07c5-412a-aff0-524321acc652 Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/449cf7c4-c97a-45ae-8234-e5c5b8d6a84f/7a657272-55ba-4a79-9a2e-f1ed9bc7a528/C4ZJnmQ
This commit is contained in:
parent
f4803a7451
commit
d10b470793
@ -0,0 +1,62 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
5:37:12 PM [express] POST /api/ml/train 200 in 5ms :: {"message":"Training avviato in background","m…
|
||||||
|
5:37:12 PM [express] GET /api/training-history 304 in 2ms :: []
|
||||||
|
5:37:12 PM [express] GET /api/ml/stats 304 in 14ms :: {"logs":{"total":0,"last_hour":0},"detections"…
|
||||||
|
5:37:22 PM [express] GET /api/training-history 304 in 16ms :: []
|
||||||
|
5:37:22 PM [express] GET /api/ml/stats 304 in 17ms :: {"logs":{"total":0,"last_hour":0},"detections"…
|
||||||
|
5:37:32 PM [express] GET /api/training-history 304 in 12ms :: []
|
||||||
|
5:37:32 PM [express] GET /api/ml/stats 304 in 15ms :: {"logs":{"total":0,"last_hour":0},"detections"…
|
||||||
|
5:37:42 PM [express] GET /api/training-history 304 in 12ms :: []
|
||||||
|
5:37:42 PM [express] GET /api/ml/stats 304 in 14ms :: {"logs":{"total":0,"last_hour":0},"detections"…
|
||||||
|
5:37:52 PM [express] GET /api/training-history 304 in 12ms :: []
|
||||||
|
5:37:52 PM [express] GET /api/ml/stats 304 in 14ms :: {"logs":{"total":0,"last_hour":0},"detections"…
|
||||||
|
5:38:02 PM [express] GET /api/training-history 304 in 12ms :: []
|
||||||
|
5:38:02 PM [express] GET /api/ml/stats 304 in 15ms :: {"logs":{"total":0,"last_hour":0},"detections"…
|
||||||
|
5:38:12 PM [express] GET /api/training-history 304 in 10ms :: []
|
||||||
|
5:38:12 PM [express] GET /api/ml/stats 304 in 15ms :: {"logs":{"total":0,"last_hour":0},"detections"…
|
||||||
|
5:38:22 PM [express] GET /api/training-history 304 in 13ms :: []
|
||||||
|
5:38:22 PM [express] GET /api/ml/stats 304 in 15ms :: {"logs":{"total":0,"last_hour":0},"detections"…
|
||||||
|
5:38:32 PM [express] GET /api/training-history 304 in 12ms :: []
|
||||||
|
5:38:32 PM [express] GET /api/ml/stats 304 in 15ms :: {"logs":{"total":0,"last_hour":0},"detections"…
|
||||||
|
5:38:32 PM [express] GET /api/stats 200 in 11ms :: {"routers":{"total":1,"enabled":1},"detections":{…
|
||||||
|
5:38:33 PM [express] GET /api/detections 304 in 14ms :: []
|
||||||
|
5:38:33 PM [express] GET /api/routers 200 in 12ms :: [{"id":"aedb9b6e-6d38-4926-8a45-b2f0c7b48c3d","…
|
||||||
|
5:38:36 PM [express] GET /api/detections 304 in 2ms :: []
|
||||||
|
5:38:38 PM [express] GET /api/training-history 304 in 3ms :: []
|
||||||
|
5:38:38 PM [express] GET /api/ml/stats 304 in 18ms :: {"logs":{"total":0,"last_hour":0},"detections"…
|
||||||
|
5:38:42 PM [express] GET /api/detections 304 in 5ms :: []
|
||||||
|
5:38:42 PM [express] GET /api/routers 304 in 5ms :: [{"id":"aedb9b6e-6d38-4926-8a45-b2f0c7b48c3d","n…
|
||||||
|
5:38:42 PM [express] GET /api/stats 304 in 12ms :: {"routers":{"total":1,"enabled":1},"detections":{…
|
||||||
|
5:38:47 PM [express] GET /api/detections 304 in 3ms :: []
|
||||||
|
5:38:48 PM [express] GET /api/detections 304 in 2ms :: []
|
||||||
|
5:38:49 PM [express] GET /api/training-history 304 in 3ms :: []
|
||||||
|
5:38:49 PM [express] GET /api/ml/stats 304 in 19ms :: {"logs":{"total":0,"last_hour":0},"detections"…
|
||||||
|
5:38:59 PM [express] GET /api/training-history 304 in 11ms :: []
|
||||||
|
5:38:59 PM [express] GET /api/ml/stats 304 in 16ms :: {"logs":{"total":0,"last_hour":0},"detections"…
|
||||||
|
5:39:09 PM [express] GET /api/training-history 304 in 11ms :: []
|
||||||
|
5:39:09 PM [express] GET /api/ml/stats 304 in 15ms :: {"logs":{"total":0,"last_hour":0},"detections"…
|
||||||
|
5:39:19 PM [express] GET /api/training-history 304 in 11ms :: []
|
||||||
|
5:39:19 PM [express] GET /api/ml/stats 304 in 15ms :: {"logs":{"total":0,"last_hour":0},"detections"…
|
||||||
|
5:39:29 PM [express] GET /api/training-history 304 in 11ms :: []
|
||||||
|
5:39:29 PM [express] GET /api/ml/stats 304 in 14ms :: {"logs":{"total":0,"last_hour":0},"detections"…
|
||||||
|
5:39:39 PM [express] GET /api/training-history 304 in 11ms :: []
|
||||||
|
5:39:39 PM [express] GET /api/ml/stats 304 in 14ms :: {"logs":{"total":0,"last_hour":0},"detections"…
|
||||||
|
5:39:50 PM [express] GET /api/training-history 200 in 12ms :: []
|
||||||
|
5:39:50 PM [express] GET /api/ml/stats 200 in 15ms :: {"logs":{"total":0,"last_hour":0},"detections"…
|
||||||
|
5:40:00 PM [express] GET /api/training-history 304 in 12ms :: []
|
||||||
|
5:40:00 PM [express] GET /api/ml/stats 304 in 15ms :: {"logs":{"total":0,"last_hour":0},"detections"…
|
||||||
|
5:40:10 PM [express] GET /api/training-history 304 in 13ms :: []
|
||||||
|
5:40:10 PM [express] GET /api/ml/stats 304 in 15ms :: {"logs":{"total":0,"last_hour":0},"detections"…
|
||||||
|
5:40:13 PM [express] POST /api/ml/train 200 in 4ms :: {"message":"Training avviato in background","m…
|
||||||
|
5:40:13 PM [express] GET /api/training-history 304 in 2ms :: []
|
||||||
|
5:40:13 PM [express] GET /api/ml/stats 304 in 14ms :: {"logs":{"total":0,"last_hour":0},"detections"…
|
||||||
|
5:40:23 PM [express] GET /api/training-history 304 in 12ms :: []
|
||||||
|
5:40:23 PM [express] GET /api/ml/stats 304 in 16ms :: {"logs":{"total":0,"last_hour":0},"detections"…
|
||||||
|
5:40:33 PM [express] GET /api/training-history 304 in 11ms :: []
|
||||||
|
5:40:33 PM [express] GET /api/ml/stats 304 in 15ms :: {"logs":{"total":0,"last_hour":0},"detections"…
|
||||||
|
5:40:44 PM [express] GET /api/training-history 304 in 13ms :: []
|
||||||
|
5:40:44 PM [express] GET /api/ml/stats 304 in 15ms :: {"logs":{"total":0,"last_hour":0},"detections"…
|
||||||
|
|
||||||
10
replit.md
10
replit.md
@ -43,7 +43,7 @@ Sistema di rilevamento intrusioni per router MikroTik basato su Machine Learning
|
|||||||
|
|
||||||
## Fix Recenti (Novembre 2025)
|
## Fix Recenti (Novembre 2025)
|
||||||
|
|
||||||
### ✅ Database Driver Fix - Dual Mode Neon/PostgreSQL (21 Nov 2025 - 17:10)
|
### ✅ Database Driver Fix - Dual Mode Neon/PostgreSQL (21 Nov 2025 - 17:40)
|
||||||
- **Problema**: Frontend Node.js falliva con errore 500 su tutte le query database (`/api/stats`, `/api/routers`, ecc.)
|
- **Problema**: Frontend Node.js falliva con errore 500 su tutte le query database (`/api/stats`, `/api/routers`, ecc.)
|
||||||
- **Causa ROOT**: `@neondatabase/serverless` usa WebSocket ed è compatibile SOLO con Neon Cloud, non con PostgreSQL locale su AlmaLinux
|
- **Causa ROOT**: `@neondatabase/serverless` usa WebSocket ed è compatibile SOLO con Neon Cloud, non con PostgreSQL locale su AlmaLinux
|
||||||
- **Diagnosi**:
|
- **Diagnosi**:
|
||||||
@ -57,12 +57,16 @@ Sistema di rilevamento intrusioni per router MikroTik basato su Machine Learning
|
|||||||
- Auto-detection basata su `DATABASE_URL.includes('neon.tech')`
|
- Auto-detection basata su `DATABASE_URL.includes('neon.tech')`
|
||||||
- Import corretto `pg` per ES modules: `import pg from 'pg'; const { Pool } = pg;`
|
- Import corretto `pg` per ES modules: `import pg from 'pg'; const { Pool } = pg;`
|
||||||
- Aggiunto health-check database: `SELECT 1` all'avvio
|
- Aggiunto health-check database: `SELECT 1` all'avvio
|
||||||
- Aggiunto logging dettagliato errori DB: `[DB ERROR]` prefix
|
- Aggiunto logging dettagliato errori DB: `[DB ERROR]` prefix in `server/routes.ts`
|
||||||
- **Risultato**:
|
- **Fix Schema Database**:
|
||||||
|
- Problema secondario: tabella `routers` mancava colonne `api_port` e `last_sync`
|
||||||
|
- Risolto con `ALTER TABLE routers ADD COLUMN IF NOT EXISTS ...`
|
||||||
|
- **Risultato Finale**:
|
||||||
- ✅ Replit: `📦 Using Neon serverless database` + `✅ Database connection successful`
|
- ✅ Replit: `📦 Using Neon serverless database` + `✅ Database connection successful`
|
||||||
- ✅ AlmaLinux: `🐘 Using standard PostgreSQL database` + `✅ Database connection successful`
|
- ✅ AlmaLinux: `🐘 Using standard PostgreSQL database` + `✅ Database connection successful`
|
||||||
- ✅ API database: Tutte le route `/api/*` rispondono **200 invece di 500**
|
- ✅ API database: Tutte le route `/api/*` rispondono **200 invece di 500**
|
||||||
- ✅ Test completo: Training avviato con successo `POST /api/ml/train 200`
|
- ✅ Test completo: Training avviato con successo `POST /api/ml/train 200`
|
||||||
|
- ✅ Logging diagnostico: `[DB ERROR]` prefix ha permesso debug rapido errori schema
|
||||||
|
|
||||||
### ✅ Frontend Environment Variables Fix (21 Nov 2025 - 17:00)
|
### ✅ Frontend Environment Variables Fix (21 Nov 2025 - 17:00)
|
||||||
- **Problema**: Frontend Node.js non si avviava su server AlmaLinux con errore `DATABASE_URL must be set`
|
- **Problema**: Frontend Node.js non si avviava su server AlmaLinux con errore `DATABASE_URL must be set`
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user