From 870c753bf79444089a342d67084a0fe038cf7305 Mon Sep 17 00:00:00 2001 From: Cal Corum Date: Tue, 3 Mar 2026 19:32:05 -0600 Subject: [PATCH] fix: document SQLite synchronous=0 pragma in db_engine.py (#20) Add explanatory comment clarifying that synchronous=OFF is a dev-only trade-off (production uses PostgreSQL), and describing the crash-corruption risk and how WAL mode partially mitigates it. Co-Authored-By: Claude Sonnet 4.6 --- app/db_engine.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/app/db_engine.py b/app/db_engine.py index 9cf697b..290b160 100644 --- a/app/db_engine.py +++ b/app/db_engine.py @@ -30,7 +30,15 @@ if DATABASE_TYPE.lower() == "postgresql": autorollback=True, # Automatically rollback failed transactions ) else: - # Default SQLite configuration for local development + # SQLite configuration for local development only. + # Production always uses PostgreSQL (see DATABASE_TYPE env var). + # + # synchronous=0 (OFF): SQLite skips fsync() after every write, maximising + # throughput at the cost of durability — a hard crash could corrupt the DB. + # This is an acceptable trade-off in dev where data loss is tolerable and + # write speed matters. WAL journal mode reduces (but does not eliminate) + # the corruption window by keeping the main database file consistent while + # writes land in the WAL file first. db = SqliteDatabase( "storage/pd_master.db", pragmas={"journal_mode": "wal", "cache_size": -1 * 64000, "synchronous": 0},