Fix UI DuckDB concurrent access with read-only mode
All checks were successful
CI/CD Pipeline / test (push) Successful in 1m46s
CI/CD Pipeline / build-engine (push) Has been skipped
CI/CD Pipeline / build-ui (push) Has been skipped

- Add read_only parameter to DataStorage.connect()
- UI now connects in read-only mode to avoid lock conflicts with engine
This commit is contained in:
bnair123
2025-12-27 23:43:25 +04:00
parent 007633660c
commit 8a4750c45e
2 changed files with 8 additions and 6 deletions

View File

@@ -27,22 +27,24 @@ class DataStorage:
storage.disconnect()
"""
def __init__(self, db_path: Path) -> None:
def __init__(self, db_path: Path, *, read_only: bool = False) -> None:
"""Initialize storage with database path.
Args:
db_path: Path to DuckDB database file
read_only: If True, open database in read-only mode (no locking)
"""
self.db_path = db_path
self._read_only = read_only
self._conn: duckdb.DuckDBPyConnection | None = None
def connect(self) -> None:
"""Connect to the database."""
# Ensure parent directory exists
self.db_path.parent.mkdir(parents=True, exist_ok=True)
if not self._read_only:
self.db_path.parent.mkdir(parents=True, exist_ok=True)
self._conn = duckdb.connect(str(self.db_path))
logger.info("Connected to DuckDB", path=str(self.db_path))
self._conn = duckdb.connect(str(self.db_path), read_only=self._read_only)
logger.info("Connected to DuckDB", path=str(self.db_path), read_only=self._read_only)
def disconnect(self) -> None:
"""Close database connection."""

View File

@@ -33,7 +33,7 @@ def get_storage() -> DataStorage | None:
if not db_path.exists():
return None
storage = DataStorage(db_path)
storage = DataStorage(db_path, read_only=True)
storage.connect()
return storage