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