From 32d420dace599f163acb6eea35512f712ee6026c Mon Sep 17 00:00:00 2001 From: tinkle-community Date: Tue, 9 Dec 2025 20:01:45 +0800 Subject: [PATCH] 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 --- main.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 620aea30..386db295 100644 --- a/main.go +++ b/main.go @@ -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)