fix(db): enable WAL mode, busy_timeout and single conn to avoid SQLITE_BUSY
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
BINARY=nasctl
|
||||
VERSION?=0.7.5
|
||||
VERSION?=0.7.6
|
||||
GO?=go
|
||||
LDFLAGS=-s -w -X github.com/darroyo/nasctl/internal/web.Version=$(VERSION) -X github.com/darroyo/nasctl/internal/web.Commit=$(shell git rev-parse --short HEAD 2>/dev/null || echo unknown)
|
||||
BUILD_FLAGS=CGO_ENABLED=0
|
||||
|
||||
@@ -25,10 +25,19 @@ func Open(path string) (*DB, error) {
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("open sqlite: %w", err)
|
||||
}
|
||||
if _, err := conn.Exec(`PRAGMA journal_mode = WAL`); err != nil {
|
||||
_ = conn.Close()
|
||||
return nil, fmt.Errorf("set journal_mode: %w", err)
|
||||
}
|
||||
if _, err := conn.Exec(`PRAGMA busy_timeout = 5000`); err != nil {
|
||||
_ = conn.Close()
|
||||
return nil, fmt.Errorf("set busy_timeout: %w", err)
|
||||
}
|
||||
if _, err := conn.Exec(`PRAGMA foreign_keys = ON`); err != nil {
|
||||
_ = conn.Close()
|
||||
return nil, fmt.Errorf("enable foreign keys: %w", err)
|
||||
}
|
||||
conn.SetMaxOpenConns(1)
|
||||
return &DB{conn: conn}, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user