Rename sync_series_from_data_files to sync_legacy_series_to_db
- Rename function to reflect its legacy status - Add deprecation warning log on execution - Update all callers (initialization_service, api/config, fastapi_app) - Update tests to use new name - Add deprecation notice to DEVELOPMENT.md Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -284,9 +284,9 @@ async def update_directory(
|
||||
try:
|
||||
import structlog
|
||||
|
||||
from src.server.services.anime_service import sync_series_from_data_files
|
||||
from src.server.services.anime_service import sync_legacy_series_to_db
|
||||
logger = structlog.get_logger(__name__)
|
||||
sync_count = await sync_series_from_data_files(directory, logger)
|
||||
sync_count = await sync_legacy_series_to_db(directory, logger)
|
||||
logger.info(
|
||||
"Directory updated: synced series from data files",
|
||||
directory=directory,
|
||||
|
||||
@@ -38,7 +38,6 @@ from src.server.controllers.page_controller import router as page_router
|
||||
from src.server.middleware.auth import AuthMiddleware
|
||||
from src.server.middleware.error_handler import register_exception_handlers
|
||||
from src.server.middleware.setup_redirect import SetupRedirectMiddleware
|
||||
from src.server.services.anime_service import sync_series_from_data_files
|
||||
from src.server.services.progress_service import get_progress_service
|
||||
from src.server.services.websocket_service import get_websocket_service
|
||||
|
||||
|
||||
@@ -1554,19 +1554,17 @@ def get_anime_service(series_app: SeriesApp) -> AnimeService:
|
||||
return AnimeService(series_app)
|
||||
|
||||
|
||||
async def sync_series_from_data_files(
|
||||
async def sync_legacy_series_to_db(
|
||||
anime_directory: str,
|
||||
log_instance=None # pylint: disable=unused-argument
|
||||
) -> int:
|
||||
"""
|
||||
Sync series from data files to the database.
|
||||
One-time legacy sync: import any series from 'data' files
|
||||
not already in the database.
|
||||
|
||||
Scans the anime directory for data files and adds any new series
|
||||
to the database. Existing series are skipped (no duplicates).
|
||||
|
||||
This function is typically called during application startup to ensure
|
||||
series metadata stored in filesystem data files is available in the
|
||||
database.
|
||||
Deprecated: Series are now loaded directly from the database.
|
||||
This function remains for backwards compatibility with legacy
|
||||
file-based data during migration.
|
||||
|
||||
Args:
|
||||
anime_directory: Path to the anime directory with data files
|
||||
@@ -1578,6 +1576,11 @@ async def sync_series_from_data_files(
|
||||
"""
|
||||
# Always use structlog for structured logging with keyword arguments
|
||||
log = structlog.get_logger(__name__)
|
||||
|
||||
log.warning(
|
||||
"sync_legacy_series_to_db is deprecated. "
|
||||
"Series are now loaded directly from database."
|
||||
)
|
||||
|
||||
try:
|
||||
from src.server.database.connection import get_db_session
|
||||
|
||||
@@ -6,7 +6,7 @@ from typing import Callable, Optional
|
||||
import structlog
|
||||
|
||||
from src.config.settings import settings
|
||||
from src.server.services.anime_service import sync_series_from_data_files
|
||||
from src.server.services.anime_service import sync_legacy_series_to_db
|
||||
from src.server.services.legacy_file_migration import migrate_series_from_files_to_db
|
||||
|
||||
logger = structlog.get_logger(__name__)
|
||||
@@ -170,7 +170,7 @@ async def _sync_anime_folders(progress_service=None) -> int:
|
||||
metadata={"step_id": "series_sync"}
|
||||
)
|
||||
|
||||
sync_count = await sync_series_from_data_files(settings.anime_directory)
|
||||
sync_count = await sync_legacy_series_to_db(settings.anime_directory)
|
||||
logger.info("Data file sync complete. Added %d series.", sync_count)
|
||||
|
||||
if progress_service:
|
||||
|
||||
@@ -111,17 +111,17 @@ class TestGetAllSeriesFromDataFiles:
|
||||
|
||||
|
||||
class TestSyncSeriesToDatabase:
|
||||
"""Test sync_series_from_data_files function from anime_service."""
|
||||
"""Test sync_legacy_series_to_db function from anime_service."""
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_sync_with_empty_directory(self):
|
||||
"""Test sync with empty anime directory."""
|
||||
from src.server.services.anime_service import sync_series_from_data_files
|
||||
from src.server.services.anime_service import sync_legacy_series_to_db
|
||||
|
||||
with tempfile.TemporaryDirectory() as tmp_dir:
|
||||
with patch('src.core.SeriesApp.Loaders'), \
|
||||
patch('src.core.SeriesApp.SerieScanner'):
|
||||
count = await sync_series_from_data_files(tmp_dir)
|
||||
count = await sync_legacy_series_to_db(tmp_dir)
|
||||
|
||||
assert count == 0
|
||||
# Function should complete successfully with no series
|
||||
@@ -134,7 +134,7 @@ class TestSyncSeriesToDatabase:
|
||||
from files and the sync function attempts to add them to the DB.
|
||||
The actual DB interaction is tested in test_add_to_db_creates_record.
|
||||
"""
|
||||
from src.server.services.anime_service import sync_series_from_data_files
|
||||
from src.server.services.anime_service import sync_legacy_series_to_db
|
||||
|
||||
with tempfile.TemporaryDirectory() as tmp_dir:
|
||||
# Create test data files
|
||||
@@ -160,7 +160,7 @@ class TestSyncSeriesToDatabase:
|
||||
patch('src.core.SeriesApp.SerieScanner'):
|
||||
# The function should return 0 because DB isn't available
|
||||
# but should not crash
|
||||
count = await sync_series_from_data_files(tmp_dir)
|
||||
count = await sync_legacy_series_to_db(tmp_dir)
|
||||
|
||||
# Since no real DB, it will fail gracefully
|
||||
# Function returns 0 when DB operations fail
|
||||
@@ -170,7 +170,7 @@ class TestSyncSeriesToDatabase:
|
||||
@pytest.mark.asyncio
|
||||
async def test_sync_handles_exceptions_gracefully(self):
|
||||
"""Test that sync handles exceptions without crashing."""
|
||||
from src.server.services.anime_service import sync_series_from_data_files
|
||||
from src.server.services.anime_service import sync_legacy_series_to_db
|
||||
|
||||
# Make SeriesApp raise an exception during initialization
|
||||
with patch('src.core.SeriesApp.Loaders'), \
|
||||
@@ -179,7 +179,7 @@ class TestSyncSeriesToDatabase:
|
||||
'src.core.SeriesApp.SerieList',
|
||||
side_effect=Exception("Test error")
|
||||
):
|
||||
count = await sync_series_from_data_files("/fake/path")
|
||||
count = await sync_legacy_series_to_db("/fake/path")
|
||||
|
||||
assert count == 0
|
||||
# Function should complete without crashing
|
||||
|
||||
@@ -21,7 +21,7 @@ class TestInitializationWorkflow:
|
||||
async def test_perform_initial_setup_with_mocked_dependencies(self):
|
||||
"""Test initial setup completes with minimal mocking."""
|
||||
# Mock only the external dependencies
|
||||
with patch('src.server.services.anime_service.sync_series_from_data_files') as mock_sync:
|
||||
with patch('src.server.services.anime_service.sync_legacy_series_to_db') as mock_sync:
|
||||
mock_sync.return_value = 0 # No series to sync
|
||||
|
||||
# Call the actual function
|
||||
@@ -241,9 +241,9 @@ class TestModuleStructure:
|
||||
assert hasattr(initialization_service, 'settings')
|
||||
|
||||
def test_sync_series_function_imported(self):
|
||||
"""Test sync_series_from_data_files is imported."""
|
||||
assert hasattr(initialization_service, 'sync_series_from_data_files')
|
||||
assert callable(initialization_service.sync_series_from_data_files)
|
||||
"""Test sync_legacy_series_to_db is imported."""
|
||||
assert hasattr(initialization_service, 'sync_legacy_series_to_db')
|
||||
assert callable(initialization_service.sync_legacy_series_to_db)
|
||||
|
||||
|
||||
# Simpler integration tests that don't require complex mocking
|
||||
@@ -413,7 +413,7 @@ class TestInitialSetupWorkflow:
|
||||
async def test_initial_setup_already_completed(self):
|
||||
"""Test initial setup when already completed."""
|
||||
with patch.object(initialization_service, '_check_initial_scan_status', return_value=True), \
|
||||
patch('src.server.services.anime_service.sync_series_from_data_files'):
|
||||
patch('src.server.services.anime_service.sync_legacy_series_to_db'):
|
||||
|
||||
result = await initialization_service.perform_initial_setup()
|
||||
|
||||
@@ -425,7 +425,7 @@ class TestInitialSetupWorkflow:
|
||||
"""Test initial setup with no directory configured."""
|
||||
with patch.object(initialization_service, '_check_initial_scan_status', return_value=False), \
|
||||
patch.object(initialization_service, '_validate_anime_directory', return_value=False), \
|
||||
patch('src.server.services.anime_service.sync_series_from_data_files'):
|
||||
patch('src.server.services.anime_service.sync_legacy_series_to_db'):
|
||||
|
||||
result = await initialization_service.perform_initial_setup()
|
||||
|
||||
@@ -440,7 +440,7 @@ class TestInitialSetupWorkflow:
|
||||
patch.object(initialization_service, '_sync_anime_folders', return_value=5), \
|
||||
patch.object(initialization_service, '_mark_initial_scan_completed'), \
|
||||
patch.object(initialization_service, '_load_series_into_memory'), \
|
||||
patch('src.server.services.anime_service.sync_series_from_data_files'):
|
||||
patch('src.server.services.anime_service.sync_legacy_series_to_db'):
|
||||
|
||||
mock_progress = AsyncMock()
|
||||
result = await initialization_service.perform_initial_setup(mock_progress)
|
||||
@@ -456,7 +456,7 @@ class TestInitialSetupWorkflow:
|
||||
with patch.object(initialization_service, '_check_initial_scan_status', return_value=False), \
|
||||
patch.object(initialization_service, '_validate_anime_directory', return_value=True), \
|
||||
patch.object(initialization_service, '_sync_anime_folders', side_effect=OSError("Disk error")), \
|
||||
patch('src.server.services.anime_service.sync_series_from_data_files'):
|
||||
patch('src.server.services.anime_service.sync_legacy_series_to_db'):
|
||||
|
||||
result = await initialization_service.perform_initial_setup()
|
||||
|
||||
@@ -469,7 +469,7 @@ class TestInitialSetupWorkflow:
|
||||
with patch.object(initialization_service, '_check_initial_scan_status', return_value=False), \
|
||||
patch.object(initialization_service, '_validate_anime_directory', return_value=True), \
|
||||
patch.object(initialization_service, '_sync_anime_folders', side_effect=RuntimeError("DB error")), \
|
||||
patch('src.server.services.anime_service.sync_series_from_data_files'):
|
||||
patch('src.server.services.anime_service.sync_legacy_series_to_db'):
|
||||
|
||||
result = await initialization_service.perform_initial_setup()
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ import pytest
|
||||
from src.server.services.anime_service import (
|
||||
AnimeService,
|
||||
AnimeServiceError,
|
||||
sync_series_from_data_files,
|
||||
sync_legacy_series_to_db,
|
||||
)
|
||||
from src.server.services.progress_service import ProgressService
|
||||
|
||||
@@ -1303,7 +1303,7 @@ class TestGetNFOStatisticsSelfManaged:
|
||||
|
||||
|
||||
class TestSyncSeriesFromDataFiles:
|
||||
"""Test module-level sync_series_from_data_files function."""
|
||||
"""Test module-level sync_legacy_series_to_db function."""
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_sync_adds_new_series(self, tmp_path):
|
||||
@@ -1343,7 +1343,7 @@ class TestSyncSeriesFromDataFiles:
|
||||
]
|
||||
MockApp.return_value = mock_app_instance
|
||||
|
||||
count = await sync_series_from_data_files(str(tmp_path))
|
||||
count = await sync_legacy_series_to_db(str(tmp_path))
|
||||
|
||||
assert count == 1
|
||||
mock_create.assert_called_once()
|
||||
@@ -1382,7 +1382,7 @@ class TestSyncSeriesFromDataFiles:
|
||||
]
|
||||
MockApp.return_value = mock_app_instance
|
||||
|
||||
count = await sync_series_from_data_files(str(tmp_path))
|
||||
count = await sync_legacy_series_to_db(str(tmp_path))
|
||||
|
||||
assert count == 0
|
||||
mock_create.assert_not_called()
|
||||
@@ -1397,7 +1397,7 @@ class TestSyncSeriesFromDataFiles:
|
||||
mock_app_instance.get_all_series_from_data_files.return_value = []
|
||||
MockApp.return_value = mock_app_instance
|
||||
|
||||
count = await sync_series_from_data_files(str(tmp_path))
|
||||
count = await sync_legacy_series_to_db(str(tmp_path))
|
||||
|
||||
assert count == 0
|
||||
|
||||
@@ -1436,7 +1436,7 @@ class TestSyncSeriesFromDataFiles:
|
||||
]
|
||||
MockApp.return_value = mock_app_instance
|
||||
|
||||
count = await sync_series_from_data_files(str(tmp_path))
|
||||
count = await sync_legacy_series_to_db(str(tmp_path))
|
||||
|
||||
assert count == 1
|
||||
# The name should have been set to folder
|
||||
|
||||
@@ -160,7 +160,7 @@ class TestSyncAnimeFolders:
|
||||
@pytest.mark.asyncio
|
||||
async def test_sync_anime_folders_without_progress(self):
|
||||
"""Test syncing anime folders without progress service."""
|
||||
with patch('src.server.services.initialization_service.sync_series_from_data_files',
|
||||
with patch('src.server.services.initialization_service.sync_legacy_series_to_db',
|
||||
new_callable=AsyncMock, return_value=42) as mock_sync:
|
||||
result = await _sync_anime_folders()
|
||||
|
||||
@@ -172,7 +172,7 @@ class TestSyncAnimeFolders:
|
||||
"""Test syncing anime folders with progress updates."""
|
||||
mock_progress = AsyncMock()
|
||||
|
||||
with patch('src.server.services.initialization_service.sync_series_from_data_files',
|
||||
with patch('src.server.services.initialization_service.sync_legacy_series_to_db',
|
||||
new_callable=AsyncMock, return_value=10) as mock_sync:
|
||||
result = await _sync_anime_folders(progress_service=mock_progress)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user