Do not run db upgrades when creating a new db

This commit is contained in:
Yiorgis Gozadinos 2025-09-25 10:52:11 +03:00
parent 039daa949a
commit 184fd12e42
No known key found for this signature in database
2 changed files with 32 additions and 1 deletions

View file

@ -157,7 +157,8 @@ class Store:
current_version = metadata.version("haiku.rag")
db_version = self.get_haiku_version()
run_pending_upgrades(self, db_version, current_version)
if db_version != "0.0.0":
run_pending_upgrades(self, db_version, current_version)
# After upgrades complete (or if none), set stored version
# to the greater of the installed package version and the

View file

@ -92,3 +92,33 @@ async def test_version_rollback_on_update_failure(temp_db_path):
chunks_repo = ChunkRepository(store)
original_chunks = await chunks_repo.get_by_document_id(created.id) # type: ignore[arg-type]
assert len(original_chunks) > 0
def test_new_database_does_not_run_upgrades(monkeypatch, temp_db_path):
def fail_if_called(*_args, **_kwargs):
raise AssertionError("run_pending_upgrades should not be called for new DB")
monkeypatch.setattr(
"haiku.rag.store.upgrades.run_pending_upgrades",
fail_if_called,
)
Store(temp_db_path)
def test_existing_database_runs_upgrades(monkeypatch, temp_db_path):
Store(temp_db_path)
called = {"value": False}
def mark_called(*_args, **_kwargs):
called["value"] = True
monkeypatch.setattr(
"haiku.rag.store.upgrades.run_pending_upgrades",
mark_called,
)
Store(temp_db_path)
assert called["value"]