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:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user