Update SQLite configuration for on-disk database storage

- Add ClassVar type annotation for DB_DIR in config.py
- Add Base import in base.py for proper Alembic migrations
- Update README with detailed SQLite configuration information

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Automated Action 2025-05-11 19:17:11 +00:00
parent d2d0b364aa
commit f27201a3a6
3 changed files with 12 additions and 2 deletions

View File

@ -15,7 +15,7 @@ A Todo application backend built with Python, FastAPI, and SQLAlchemy.
- **SQLAlchemy**: SQL toolkit and ORM
- **Alembic**: Database migration tool
- **Pydantic**: Data validation and settings management
- **SQLite**: Lightweight disk-based database
- **SQLite**: Lightweight disk-based database (stored in `/storage/db/db.sqlite`)
- **Uvicorn**: ASGI server
## Project Structure
@ -55,12 +55,19 @@ A Todo application backend built with Python, FastAPI, and SQLAlchemy.
```
alembic upgrade head
```
This will create the SQLite database file at `/storage/db/db.sqlite`
4. Start the server:
```
uvicorn main:app --reload
```
### Database Configuration
The application uses SQLite as its database backend. The database file is stored at `/storage/db/db.sqlite`, outside the project root directory for better data isolation. The directory is automatically created if it doesn't exist.
To change the database location, modify the `DB_DIR` variable in `app/core/config.py`.
### API Documentation
Once the server is running, you can access:

View File

@ -1,4 +1,5 @@
from pathlib import Path
from typing import ClassVar
from pydantic_settings import BaseSettings
BASE_DIR = Path(__file__).resolve().parent.parent.parent
@ -9,8 +10,9 @@ class Settings(BaseSettings):
API_V1_STR: str = "/api/v1"
# Database
DB_DIR = BASE_DIR.parent / "storage" / "db"
DB_DIR: ClassVar[Path] = BASE_DIR.parent / "storage" / "db"
DB_DIR.mkdir(parents=True, exist_ok=True)
SQLALCHEMY_DATABASE_URL: str = f"sqlite:///{DB_DIR}/db.sqlite"

View File

@ -1,2 +1,3 @@
# Import all models here for Alembic to detect
from app.db.session import Base
from app.models.todo import Todo