mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-08-03 01:22:17 +00:00
Add document_llmindex migrate, a cheap check-only path (no reindex) safe to run unconditionally: has_pending_migration() short-circuits to a metadata-only read once the store is current, so a healthy install pays almost nothing. If a pending migration would require re-embedding, it only logs a warning and leaves the index as-is -- re-embedding can be slow and, for a metered embedding backend, cost money, so it stays a deliberate manual action (document_llmindex rebuild), never automatic. Wire it into the Docker image as a new init-llmindex-migrate oneshot (modeled on init-search-index, gated on init-migrations), and document the equivalent manual step for bare-metal upgrades. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
43 lines
1.5 KiB
Python
43 lines
1.5 KiB
Python
from __future__ import annotations
|
|
|
|
from typing import TYPE_CHECKING
|
|
|
|
from django.core.management import call_command
|
|
|
|
if TYPE_CHECKING:
|
|
from pytest_mock import MockerFixture
|
|
|
|
_COMPACT = "documents.management.commands.document_llmindex.llm_index_compact"
|
|
_MIGRATE = "documents.management.commands.document_llmindex.llm_index_migrate"
|
|
_INDEX = "documents.management.commands.document_llmindex.llmindex_index"
|
|
|
|
|
|
class TestDocumentLlmindexCommand:
|
|
def test_compact_calls_llm_index_compact(self, mocker: MockerFixture) -> None:
|
|
mock_compact = mocker.patch(_COMPACT)
|
|
call_command("document_llmindex", "compact")
|
|
mock_compact.assert_called_once_with()
|
|
|
|
def test_migrate_calls_llm_index_migrate(self, mocker: MockerFixture) -> None:
|
|
mock_migrate = mocker.patch(_MIGRATE)
|
|
call_command("document_llmindex", "migrate")
|
|
mock_migrate.assert_called_once_with()
|
|
|
|
def test_rebuild_calls_llmindex_index_with_rebuild_true(
|
|
self,
|
|
mocker: MockerFixture,
|
|
) -> None:
|
|
mock_index = mocker.patch(_INDEX)
|
|
call_command("document_llmindex", "rebuild")
|
|
mock_index.assert_called_once()
|
|
assert mock_index.call_args.kwargs["rebuild"] is True
|
|
|
|
def test_update_calls_llmindex_index_with_rebuild_false(
|
|
self,
|
|
mocker: MockerFixture,
|
|
) -> None:
|
|
mock_index = mocker.patch(_INDEX)
|
|
call_command("document_llmindex", "update")
|
|
mock_index.assert_called_once()
|
|
assert mock_index.call_args.kwargs["rebuild"] is False
|