Debug DB problem

This commit is contained in:
2026-01-28 02:19:54 +00:00
parent d3d5f5a3c8
commit 53362b8061
2 changed files with 20 additions and 1 deletions
+4 -1
View File
@@ -248,10 +248,13 @@ class JsonlStore:
# Check for out-of-transaction modifications # Check for out-of-transaction modifications
current_state = msgspec.to_builtins(self.db) current_state = msgspec.to_builtins(self.db)
if current_state != self._previous_builtins: if current_state != self._previous_builtins:
diff = compute_diff(self._previous_builtins, current_state)
diff_json = json.dumps(diff, default=str, indent=2)
_logger.error( _logger.error(
"Database state modified outside of transaction! " "Database state modified outside of transaction! "
"This indicates a bug where DB changes occurred without a transaction wrapper. " "This indicates a bug where DB changes occurred without a transaction wrapper. "
"Resetting to last known state from JSONL file." "Resetting to last known state from JSONL file.\n"
f"Changes detected:\n{diff_json}"
) )
# Hard reset to last known good state # Hard reset to last known good state
decoder = msgspec.json.Decoder(DB) decoder = msgspec.json.Decoder(DB)
+16
View File
@@ -31,4 +31,20 @@ def apply_migrations(data_dict: dict) -> bool:
migrated = True migrated = True
_logger.info("Applied schema migration: v0 -> v1 (removed org.created_at)") _logger.info("Applied schema migration: v0 -> v1 (removed org.created_at)")
if db_version < 2:
# Migration v1 -> v2: Convert null ip/user_agent to empty strings in sessions
if "sessions" in data_dict:
for session_data in data_dict["sessions"].values():
if session_data.get("ip") is None:
session_data["ip"] = ""
if session_data.get("user_agent") is None:
session_data["user_agent"] = ""
if session_data.get("host") is None:
session_data["host"] = ""
data_dict["v"] = 2
migrated = True
_logger.info(
"Applied schema migration: v1 -> v2 (null session fields -> empty strings)"
)
return migrated return migrated