Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/superlocalmemory/storage/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ def __init__(self, db_path: str | Path) -> None:
def _enable_wal(self) -> None:
conn = sqlite3.connect(str(self.db_path))
try:
conn.execute(f"PRAGMA busy_timeout={_BUSY_TIMEOUT_MS}") # FIRST — so WAL pragma below uses configured timeout
conn.execute("PRAGMA journal_mode=WAL")
conn.execute(f"PRAGMA busy_timeout={_BUSY_TIMEOUT_MS}")
conn.execute("PRAGMA foreign_keys=ON")
conn.commit()
finally:
Expand Down
18 changes: 18 additions & 0 deletions tests/test_storage/test_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,3 +459,21 @@ def test_list_tables(self, db: DatabaseManager) -> None:
assert "memories" in tables
assert "atomic_facts" in tables
assert "canonical_entities" in tables


# ---------------------------------------------------------------------------
# WAL PRAGMA ordering
# ---------------------------------------------------------------------------

class TestEnableWal:
def test_enable_wal_sets_busy_timeout(self, tmp_path: Path) -> None:
"""_enable_wal() sets busy_timeout so subsequent connections inherit WAL mode safely."""
db_path = tmp_path / "test.db"
db = DatabaseManager(db_path)
db.initialize(__import__("superlocalmemory.storage.schema", fromlist=["schema"]))
# Verify busy_timeout is correctly configured on DatabaseManager-managed connections
timeout = db.execute("PRAGMA busy_timeout")[0][0]
assert timeout == 10000, f"Expected busy_timeout=10000, got {timeout}"
# Verify WAL mode is active
journal = db.execute("PRAGMA journal_mode")[0][0]
assert journal.lower() == "wal", f"Expected wal, got {journal}"