From b267395d8c20f8484ce4828cd3ce439ef3cc7178 Mon Sep 17 00:00:00 2001 From: Johannes Zillmann Date: Sun, 30 Nov 2025 17:28:02 -0600 Subject: [PATCH] fix: checkpoint WAL on Close() to persist writes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit SQLite WAL mode writes go to the -wal file, not the main database. Without an explicit checkpoint before Close(), writes can be stranded and lost between CLI invocations. This was causing `bd migrate` to report success but not actually persist the version update to the database. Fixes #434 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- internal/storage/sqlite/store.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/internal/storage/sqlite/store.go b/internal/storage/sqlite/store.go index 86939668..45803b92 100644 --- a/internal/storage/sqlite/store.go +++ b/internal/storage/sqlite/store.go @@ -186,9 +186,13 @@ func New(ctx context.Context, path string) (*SQLiteStorage, error) { return storage, nil } -// Close closes the database connection +// Close closes the database connection. +// It checkpoints the WAL to ensure all writes are flushed to the main database file. func (s *SQLiteStorage) Close() error { s.closed.Store(true) + // Checkpoint WAL to ensure all writes are persisted to the main database file. + // Without this, writes may be stranded in the WAL and lost between CLI invocations. + _, _ = s.db.Exec("PRAGMA wal_checkpoint(TRUNCATE)") return s.db.Close() }