#15 put every read-then-write in src/db.ts inside db.transaction(...), which is right, but it leaves one case open. bun:sqlite's db.transaction(fn) emits a plain deferred BEGIN, and src/db.ts sets PRAGMA journal_mode = WAL without a busy timeout. Inside the server that is fine — every query is synchronous and single-threaded, so nothing interleaves. But src/tty.ts is a second process on the same file, so the web page and the ssh terminal really are two writers.
With a deferred BEGIN, a transaction that reads first and writes second takes its snapshot at the read; if the other process commits in between, the upgrade fails. Reproduced on bun 1.3.14 against the branch's schema:
A: BEGIN; SELECT ... -- server's moveCard reads its siblings
B: UPDATE ... -- tty commits a move
A: UPDATE ... -> SQLiteError: database is locked
No amount of waiting fixes that one (SQLITE_BUSY_SNAPSHOT is not retryable), and without busy_timeout even plain lock contention throws at once instead of waiting.
Done looks like
Files
src/db.ts, src/db.test.ts.
Risks
.immediate() serialises writers; with busy_timeout a slow write makes the other side wait rather than error, which is the trade we want. The nested case (createBoard -> createColumn) uses savepoints and must keep working. Until this lands, a collision surfaces as a bare 500 with no security headers, which is #20's error boundary.
#15 put every read-then-write in
src/db.tsinsidedb.transaction(...), which is right, but it leaves one case open.bun:sqlite'sdb.transaction(fn)emits a plain deferredBEGIN, andsrc/db.tssetsPRAGMA journal_mode = WALwithout a busy timeout. Inside the server that is fine — every query is synchronous and single-threaded, so nothing interleaves. Butsrc/tty.tsis a second process on the same file, so the web page and the ssh terminal really are two writers.With a deferred
BEGIN, a transaction that reads first and writes second takes its snapshot at the read; if the other process commits in between, the upgrade fails. Reproduced on bun 1.3.14 against the branch's schema:No amount of waiting fixes that one (SQLITE_BUSY_SNAPSHOT is not retryable), and without
busy_timeouteven plain lock contention throws at once instead of waiting.Done looks like
Files
src/db.ts,src/db.test.ts.Risks
.immediate()serialises writers; withbusy_timeouta slow write makes the other side wait rather than error, which is the trade we want. The nested case (createBoard->createColumn) uses savepoints and must keep working. Until this lands, a collision surfaces as a bare 500 with no security headers, which is #20's error boundary.