From f868bc59d18a5bac4da5e2bd0c6166ec9bdd6f8b Mon Sep 17 00:00:00 2001 From: Leo Vasanko Date: Wed, 28 Jan 2026 01:58:36 +0000 Subject: [PATCH] Fix migration logic. --- paskia/db/jsonl.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/paskia/db/jsonl.py b/paskia/db/jsonl.py index 4490cac..59d7c02 100644 --- a/paskia/db/jsonl.py +++ b/paskia/db/jsonl.py @@ -4,6 +4,7 @@ JSONL persistence layer for the database. from __future__ import annotations +import copy import json import logging import sys @@ -173,19 +174,24 @@ class JsonlStore: try: data_dict = await load_jsonl(self.db_path) if data_dict: - # Apply schema migrations + # Preserve original state before migrations (deep copy for nested dicts) + original_dict = copy.deepcopy(data_dict) + + # Apply schema migrations (modifies data_dict in place) migrated = apply_migrations(data_dict) decoder = msgspec.json.Decoder(DB) self.db = decoder.decode(msgspec.json.encode(data_dict)) self.db._store = self - self._previous_builtins = data_dict - - # Persist migration + + # Persist migration by setting previous state to pre-migration if migrated: + self._previous_builtins = original_dict with self.transaction("migrate"): pass # Trigger change detection await self.flush() + else: + self._previous_builtins = data_dict except ValueError: if self.db_path.exists(): raise