From f27201a3a61c800598f9530dd4a1844ae3033441 Mon Sep 17 00:00:00 2001 From: Automated Action Date: Sun, 11 May 2025 19:17:11 +0000 Subject: [PATCH] Update SQLite configuration for on-disk database storage MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 --- README.md | 9 ++++++++- app/core/config.py | 4 +++- app/db/base.py | 1 + 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c4cd594..79b7b5d 100644 --- a/README.md +++ b/README.md @@ -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: diff --git a/app/core/config.py b/app/core/config.py index 8498f41..ba3df35 100644 --- a/app/core/config.py +++ b/app/core/config.py @@ -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" diff --git a/app/db/base.py b/app/db/base.py index 0ac23ab..3d325d8 100644 --- a/app/db/base.py +++ b/app/db/base.py @@ -1,2 +1,3 @@ # Import all models here for Alembic to detect +from app.db.session import Base from app.models.todo import Todo \ No newline at end of file