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:
tinkle-community
2025-12-09 20:01:45 +08:00
parent e6f4c9a0ef
commit 32d420dace
+9 -1
View File
@@ -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)