fix: add SQLite database recovery and WAL mode for corruption resilience

- Add scripts/db-recovery.sh for database integrity check and recovery
- Enable WAL mode verification with logging on startup
- Add structured error logging to uptime handlers with monitor context
- Add comprehensive database maintenance documentation

Fixes heartbeat history showing "No History Available" due to database
corruption affecting 6 out of 14 monitors.
This commit is contained in:
GitHub Actions
2025-12-17 14:46:00 +00:00
parent da4fb33006
commit f094123123
10 changed files with 2762 additions and 1533 deletions

View File

@@ -6,6 +6,7 @@ import (
"fmt"
"strings"
"github.com/Wikid82/charon/backend/internal/logger"
"gorm.io/driver/sqlite"
"gorm.io/gorm"
)
@@ -43,6 +44,14 @@ func Connect(dbPath string) (*gorm.DB, error) {
}
configurePool(sqlDB)
// Verify WAL mode is enabled and log confirmation
var journalMode string
if err := db.Raw("PRAGMA journal_mode").Scan(&journalMode).Error; err != nil {
logger.Log().WithError(err).Warn("Failed to verify SQLite journal mode")
} else {
logger.Log().WithField("journal_mode", journalMode).Info("SQLite database connected with WAL mode enabled")
}
return db, nil
}