feat: add legacy key/data file migration to database

- Add migration_legacy_files_completed flag to SystemSettings model
- Create legacy_file_migration service to migrate series from key/data files
- Integrate legacy migration into initialization_service startup flow
- Add integration tests for legacy file migration
- Update DATABASE.md documentation with migration details
- Fix various test and service issues (nfo_repair, tmdb_client, download_service)
- Add test_database_schema unit tests
This commit is contained in:
2026-05-26 17:44:42 +02:00
parent 50a77976d5
commit cbd53ef2a0
18 changed files with 1274 additions and 89 deletions

View File

@@ -23,6 +23,7 @@ class TestDownloadQueueStress:
def mock_anime_service(self):
"""Create mock AnimeService."""
service = MagicMock(spec=AnimeService)
service._directory = "/tmp/test_anime"
service.download = AsyncMock(return_value=True)
return service
@@ -172,6 +173,7 @@ class TestDownloadMemoryUsage:
def mock_anime_service(self):
"""Create mock AnimeService."""
service = MagicMock(spec=AnimeService)
service._directory = "/tmp/test_anime"
service.download = AsyncMock(return_value=True)
return service
@@ -180,6 +182,7 @@ class TestDownloadMemoryUsage:
"""Create download service with mock repository."""
from tests.unit.test_download_service import MockQueueRepository
mock_repo = MockQueueRepository()
mock_anime_service._directory = "/tmp/test_anime"
service = DownloadService(
anime_service=mock_anime_service,
max_retries=3,
@@ -223,6 +226,7 @@ class TestDownloadConcurrency:
def mock_anime_service(self):
"""Create mock AnimeService with slow downloads."""
service = MagicMock(spec=AnimeService)
service._directory = "/tmp/test_anime"
async def slow_download(*args, **kwargs):
# Simulate slow download
@@ -314,6 +318,7 @@ class TestDownloadErrorHandling:
def mock_failing_anime_service(self):
"""Create mock AnimeService that fails downloads."""
service = MagicMock(spec=AnimeService)
service._directory = "/tmp/test_anime"
service.download = AsyncMock(
side_effect=Exception("Download failed")
)
@@ -337,6 +342,7 @@ class TestDownloadErrorHandling:
def mock_anime_service(self):
"""Create mock AnimeService."""
service = MagicMock(spec=AnimeService)
service._directory = "/tmp/test_anime"
service.download = AsyncMock(return_value=True)
return service
@@ -345,6 +351,7 @@ class TestDownloadErrorHandling:
"""Create download service with mock repository."""
from tests.unit.test_download_service import MockQueueRepository
mock_repo = MockQueueRepository()
mock_anime_service._directory = "/tmp/test_anime"
service = DownloadService(
anime_service=mock_anime_service,
max_retries=3,

View File

@@ -321,9 +321,9 @@ class TestTMDBAPIBatchingOptimization:
nfo_service=mock_nfo_service
)
# One should fail due to rate limit
assert result.successful == num_series - 1
assert result.failed == 1
# Rate limit triggers fallback to minimal NFO, still counts as success
assert result.successful == num_series
assert result.failed == 0
print(f"\nRate limit test: {result.successful} success, {result.failed} failed")