some fixes
This commit is contained in:
parent
ae77a11782
commit
e0a7c6baa9
@ -171,7 +171,7 @@ All series-related WebSocket events include `key` as the primary identifier in t
|
||||
The application uses **SQLite database** as the primary storage for anime series metadata. This replaces the legacy file-based storage system.
|
||||
|
||||
| Storage Method | Status | Location | Purpose |
|
||||
| -------------- | --------------------- | ------------------------- | ------------------------------ |
|
||||
| -------------- | --------------------- | -------------------- | ----------------------------- |
|
||||
| SQLite DB | **Primary (Current)** | `data/aniworld.db` | All series metadata and state |
|
||||
| Data Files | **Deprecated** | `{anime_dir}/*/data` | Legacy per-series JSON files |
|
||||
|
||||
|
||||
@ -288,6 +288,7 @@ async def lifespan(app: FastAPI):
|
||||
- Test duplicate key handling
|
||||
|
||||
**Implementation Notes:**
|
||||
|
||||
- Added `get_optional_database_session()` dependency in `dependencies.py` for graceful fallback
|
||||
- Endpoint saves to database when available, falls back to file-based storage when not
|
||||
- All 55 API tests and 809 unit tests pass
|
||||
@ -319,6 +320,7 @@ async def lifespan(app: FastAPI):
|
||||
- Test dependency injection provides correct sessions
|
||||
|
||||
**Implementation Notes:**
|
||||
|
||||
- Added `db_session` parameter to `SeriesApp.__init__()`
|
||||
- Added `db_session` property and `set_db_session()` method
|
||||
- Added `init_from_db_async()` for async database initialization
|
||||
@ -351,6 +353,7 @@ async def lifespan(app: FastAPI):
|
||||
- Create sample data files for migration tests
|
||||
|
||||
**Implementation Notes:**
|
||||
|
||||
- Added 5 new integration tests to cover all required test cases
|
||||
- All 11 migration integration tests pass
|
||||
- All 870 tests pass (815 unit + 55 API)
|
||||
@ -383,6 +386,7 @@ async def lifespan(app: FastAPI):
|
||||
- Verify existing file-based tests still pass ✅
|
||||
|
||||
**Implementation Notes:**
|
||||
|
||||
- Added deprecation warnings to Serie.save_to_file() and Serie.load_from_file()
|
||||
- Added deprecation warning tests to test_serie_class.py
|
||||
- Updated infrastructure.md with Data Storage section
|
||||
|
||||
@ -35,6 +35,7 @@ from src.core.providers.base_provider import Loader
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from src.server.database.models import AnimeSeries
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@ -23,6 +23,7 @@ from src.core.entities.series import Serie
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from src.server.database.models import AnimeSeries
|
||||
|
||||
|
||||
|
||||
@ -51,6 +51,15 @@ async def lifespan(app: FastAPI):
|
||||
try:
|
||||
logger.info("Starting FastAPI application...")
|
||||
|
||||
# Initialize database first (required for migration and other services)
|
||||
try:
|
||||
from src.server.database.connection import init_db
|
||||
await init_db()
|
||||
logger.info("Database initialized successfully")
|
||||
except Exception as e:
|
||||
logger.error("Failed to initialize database: %s", e, exc_info=True)
|
||||
raise # Database is required, fail startup if it fails
|
||||
|
||||
# Load configuration from config.json and sync with settings
|
||||
try:
|
||||
from src.server.services.config_service import get_config_service
|
||||
@ -128,6 +137,14 @@ async def lifespan(app: FastAPI):
|
||||
except Exception as e:
|
||||
logger.error("Error stopping download service: %s", e, exc_info=True)
|
||||
|
||||
# Close database connections
|
||||
try:
|
||||
from src.server.database.connection import close_db
|
||||
await close_db()
|
||||
logger.info("Database connections closed")
|
||||
except Exception as e:
|
||||
logger.error("Error closing database: %s", e, exc_info=True)
|
||||
|
||||
logger.info("FastAPI application shutdown complete")
|
||||
|
||||
|
||||
|
||||
@ -291,8 +291,8 @@ class TestScanSavesToDatabase:
|
||||
@pytest.mark.asyncio
|
||||
async def test_scan_async_saves_to_database(self):
|
||||
"""Test scan_async method saves series to database."""
|
||||
from src.core.SerieScanner import SerieScanner
|
||||
from src.core.entities.series import Serie
|
||||
from src.core.SerieScanner import SerieScanner
|
||||
|
||||
with tempfile.TemporaryDirectory() as tmp_dir:
|
||||
# Create series folder structure
|
||||
@ -408,8 +408,8 @@ class TestSearchAndAddWorkflow:
|
||||
@pytest.mark.asyncio
|
||||
async def test_search_and_add_workflow(self):
|
||||
"""Test searching for anime and adding it saves to database."""
|
||||
from src.core.SeriesApp import SeriesApp
|
||||
from src.core.entities.series import Serie
|
||||
from src.core.SeriesApp import SeriesApp
|
||||
|
||||
with tempfile.TemporaryDirectory() as tmp_dir:
|
||||
# Mock database
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user