mirror of
https://github.com/NoFxAiOS/nofx.git
synced 2026-07-17 01:14:40 +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:
10
main.go
10
main.go
@@ -13,6 +13,7 @@ import (
|
|||||||
"nofx/store"
|
"nofx/store"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
|
"path/filepath"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
"github.com/joho/godotenv"
|
"github.com/joho/godotenv"
|
||||||
@@ -35,10 +36,17 @@ func main() {
|
|||||||
logger.Info("✅ Configuration loaded")
|
logger.Info("✅ Configuration loaded")
|
||||||
|
|
||||||
// Initialize database
|
// 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 {
|
if len(os.Args) > 1 {
|
||||||
dbPath = 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)
|
logger.Infof("📋 Initializing database: %s", dbPath)
|
||||||
st, err := store.New(dbPath)
|
st, err := store.New(dbPath)
|
||||||
|
|||||||
Reference in New Issue
Block a user