fix: tolerate losing the WAL-switch race (pragma needs exclusive lock)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
type-two 2026-08-26 10:31:10 +10:00
parent 47412ca4b7
commit 5250dbc3ae

View File

@ -36,7 +36,10 @@ def open_db():
LIB.mkdir(parents=True, exist_ok=True) LIB.mkdir(parents=True, exist_ok=True)
THUMBS.mkdir(parents=True, exist_ok=True) THUMBS.mkdir(parents=True, exist_ok=True)
db = sqlite3.connect(DB, timeout=60) db = sqlite3.connect(DB, timeout=60)
db.execute("PRAGMA journal_mode=WAL") # concurrent index jobs on one node try: # WAL is persistent once set; the switch itself needs an exclusive
db.execute("PRAGMA journal_mode=WAL") # lock, so tolerate losing the race
except sqlite3.OperationalError:
pass
db.executescript(""" db.executescript("""
CREATE TABLE IF NOT EXISTS videos( CREATE TABLE IF NOT EXISTS videos(
id INTEGER PRIMARY KEY, path TEXT UNIQUE, mtime REAL, duration REAL, id INTEGER PRIMARY KEY, path TEXT UNIQUE, mtime REAL, duration REAL,