fixed db problem

This commit is contained in:
2026-06-03 16:15:09 -04:00
parent 820ae5d50a
commit bc4f38726a
7 changed files with 49 additions and 2 deletions
+13 -2
View File
@@ -6,9 +6,15 @@ import threading
from contextlib import contextmanager
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
DB_PATH = os.path.join(BASE_DIR, "dashboard.db")
_DEFAULT_DB_PATH = os.path.join(BASE_DIR, "data", "dashboard.db")
if os.path.exists("/.dockerenv"):
_DEFAULT_DB_PATH = "/app/data/dashboard.db"
DB_PATH = os.getenv("DASHBOARD_DB_PATH", _DEFAULT_DB_PATH)
CONFIG_JSON = os.path.join(BASE_DIR, "config.json")
os.makedirs(os.path.dirname(DB_PATH), exist_ok=True)
_conn = sqlite3.connect(DB_PATH, check_same_thread=False)
_conn.row_factory = sqlite3.Row
_lock = threading.RLock()
@@ -27,7 +33,12 @@ def _tx():
def _init_db():
with _tx():
_conn.execute("PRAGMA journal_mode=WAL;")
try:
_conn.execute("PRAGMA journal_mode=WAL;")
except sqlite3.OperationalError as exc:
# Fallback for filesystems where WAL is unavailable.
print(f"[db] WAL unavailable ({exc}); falling back to DELETE journal mode")
_conn.execute("PRAGMA journal_mode=DELETE;")
_conn.executescript(
"""
CREATE TABLE IF NOT EXISTS config (