Remove migration code and alembic dependency

This commit is contained in:
2025-12-13 09:02:26 +01:00
parent 842f9c88eb
commit ee317b29f1
13 changed files with 58 additions and 83 deletions

View File

@@ -31,7 +31,6 @@ async def setup_auth(req: SetupRequest):
This endpoint also initializes the configuration with default values
and saves the anime directory and master password hash.
If anime_directory is provided, runs migration for existing data files.
"""
if auth_service.is_configured():
raise HTTPException(

View File

@@ -214,14 +214,14 @@ def update_advanced_config(
async def update_directory(
directory_config: Dict[str, str], auth: dict = Depends(require_auth)
) -> Dict[str, Any]:
"""Update anime directory configuration and run migration.
"""Update anime directory configuration.
Args:
directory_config: Dictionary with 'directory' key
auth: Authentication token (required)
Returns:
Success message with optional migration results
Success message
"""
try:
directory = directory_config.get("directory")

View File

@@ -13,7 +13,7 @@ This package provides persistent storage for anime series, episodes, download qu
Install required dependencies:
```bash
pip install sqlalchemy alembic aiosqlite
pip install sqlalchemy aiosqlite
```
Or use the project requirements:
@@ -163,24 +163,6 @@ from src.config.settings import settings
settings.database_url = "sqlite:///./data/aniworld.db"
```
## Migrations (Future)
Alembic is installed for database migrations:
```bash
# Initialize Alembic
alembic init alembic
# Generate migration
alembic revision --autogenerate -m "Description"
# Apply migrations
alembic upgrade head
# Rollback
alembic downgrade -1
```
## Testing
Run database tests:
@@ -196,7 +178,6 @@ The test suite uses an in-memory SQLite database for isolation and speed.
- **base.py**: Base declarative class and mixins
- **models.py**: SQLAlchemy ORM models (4 models)
- **connection.py**: Engine, session factory, dependency injection
- **migrations.py**: Alembic migration placeholder
- ****init**.py**: Package exports
- **service.py**: Service layer with CRUD operations
@@ -432,5 +413,4 @@ Solution: Ensure referenced records exist before creating relationships.
## Further Reading
- [SQLAlchemy 2.0 Documentation](https://docs.sqlalchemy.org/en/20/)
- [Alembic Tutorial](https://alembic.sqlalchemy.org/en/latest/tutorial.html)
- [FastAPI with Databases](https://fastapi.tiangolo.com/tutorial/sql-databases/)

View File

@@ -313,7 +313,6 @@ async def get_schema_version(engine: Optional[AsyncEngine] = None) -> str:
"""Get current database schema version.
Returns version string based on existing tables and structure.
For production, consider using Alembic versioning.
Args:
engine: Optional database engine (uses default if not provided)

View File

@@ -51,7 +51,7 @@ async def lifespan(app: FastAPI):
try:
logger.info("Starting FastAPI application...")
# Initialize database first (required for migration and other services)
# Initialize database first (required for other services)
try:
from src.server.database.connection import init_db
await init_db()

View File

@@ -4,7 +4,7 @@ This service handles:
- Loading and saving configuration to JSON files
- Configuration validation
- Backup and restore functionality
- Configuration migration for version updates
- Configuration version management
"""
import json
@@ -35,8 +35,8 @@ class ConfigBackupError(ConfigServiceError):
class ConfigService:
"""Service for managing application configuration persistence.
Handles loading, saving, validation, backup, and migration of
configuration files. Uses JSON format for human-readable and
Handles loading, saving, validation, backup, and version management
of configuration files. Uses JSON format for human-readable and
version-control friendly storage.
"""
@@ -84,11 +84,6 @@ class ConfigService:
with open(self.config_path, "r", encoding="utf-8") as f:
data = json.load(f)
# Check if migration is needed
file_version = data.get("version", "1.0.0")
if file_version != self.CONFIG_VERSION:
data = self._migrate_config(data, file_version)
# Remove version key before constructing AppConfig
data.pop("version", None)
@@ -328,26 +323,6 @@ class ConfigService:
except (OSError, IOError):
# Ignore errors during cleanup
continue
def _migrate_config(
self, data: Dict, from_version: str # noqa: ARG002
) -> Dict:
"""Migrate configuration from old version to current.
Args:
data: Configuration data to migrate
from_version: Version to migrate from (reserved for future use)
Returns:
Dict: Migrated configuration data
"""
# Currently only one version exists
# Future migrations would go here
# Example:
# if from_version == "1.0.0" and self.CONFIG_VERSION == "2.0.0":
# data = self._migrate_1_0_to_2_0(data)
return data
# Singleton instance