fix: checkpoint WAL on Close() to persist writes

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 <noreply@anthropic.com>
This commit is contained in:
Johannes Zillmann
2025-11-30 17:28:02 -06:00
parent 9aada0fd89
commit b267395d8c

View File

@@ -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()
}