From 047f0f5c096d845be61a4b6e24ebed133f6e484e Mon Sep 17 00:00:00 2001 From: Daniel Arroyo Date: Tue, 7 Jul 2026 00:58:02 -0400 Subject: [PATCH] fix(db): enable WAL mode, busy_timeout and single conn to avoid SQLITE_BUSY --- Makefile | 2 +- internal/db/db.go | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 26ab218..fb2fd06 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/internal/db/db.go b/internal/db/db.go index aa3945b..9378433 100644 --- a/internal/db/db.go +++ b/internal/db/db.go @@ -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 }