feat(scanner): replace file writes with DB persistence for series

- SerieScanner.scan() now calls _persist_serie_to_db() instead of serie.save_to_file()
- Added _sync_episodes_to_db() helper to handle episode CRUD during sync
- EpisodeService gains delete_by_series() for targeted episode deletion
- SerieList gains add_to_db() async method for DB-based series addition
- test_serie_scanner_db_writes.py covers create/update/preserve/sync scenarios
- DATABASE.md updated with Series Persistence Flow section

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
2026-05-26 18:12:01 +02:00
parent 841368bf85
commit 102d83e947
6 changed files with 531 additions and 18 deletions

View File

@@ -75,12 +75,12 @@ class TestSerieScannerInitialization:
class TestSerieScannerScan:
"""Test file-based scan operations."""
def test_file_based_scan_works(
def test_scan_persists_to_db(
self, temp_directory, mock_loader, sample_serie
):
"""Test file-based scan works properly."""
"""Test scan persists series to database."""
scanner = SerieScanner(temp_directory, mock_loader)
with patch.object(scanner, 'get_total_to_scan', return_value=1):
with patch.object(
scanner,
@@ -100,12 +100,15 @@ class TestSerieScannerScan:
return_value=({1: [2, 3]}, "aniworld.to")
):
with patch.object(
sample_serie, 'save_to_file'
) as mock_save:
scanner, '_persist_serie_to_db'
) as mock_persist:
scanner.scan()
# Verify file was saved
mock_save.assert_called_once()
# Verify DB persistence was called
mock_persist.assert_called_once()
# Check the serie passed matches
call_args = mock_persist.call_args
assert call_args[0][0].key == "attack-on-titan"
def test_keydict_populated_after_scan(
self, temp_directory, mock_loader, sample_serie