mirror of
https://github.com/laoxong/nofx.git
synced 2026-06-04 09:58:22 +08:00
fix: change database path to data/data.db for Docker volume persistence
- Changed default dbPath from 'data.db' to 'data/data.db' - This ensures database is stored in /app/data/ which is mounted as Docker volume - Added automatic creation of data directory if it doesn't exist - Fixes issue where database was lost on container restart
This commit is contained in:
@@ -13,6 +13,7 @@ import (
|
||||
"nofx/store"
|
||||
"os"
|
||||
"os/signal"
|
||||
"path/filepath"
|
||||
"syscall"
|
||||
|
||||
"github.com/joho/godotenv"
|
||||
@@ -35,10 +36,17 @@ func main() {
|
||||
logger.Info("✅ Configuration loaded")
|
||||
|
||||
// Initialize database
|
||||
dbPath := "data.db"
|
||||
// Default path is data/data.db to work with Docker volume mount (/app/data)
|
||||
dbPath := "data/data.db"
|
||||
if len(os.Args) > 1 {
|
||||
dbPath = os.Args[1]
|
||||
}
|
||||
// Ensure data directory exists
|
||||
if dir := filepath.Dir(dbPath); dir != "." {
|
||||
if err := os.MkdirAll(dir, 0755); err != nil {
|
||||
logger.Errorf("Failed to create data directory: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
logger.Infof("📋 Initializing database: %s", dbPath)
|
||||
st, err := store.New(dbPath)
|
||||
|
||||
Reference in New Issue
Block a user