diff --git a/backend/.env.example b/backend/.env.example index fd42e4c..c831f49 100644 --- a/backend/.env.example +++ b/backend/.env.example @@ -1,3 +1,4 @@ APP_NAME="Temis RiskControl API" APP_VERSION="0.1.0" DEBUG=false +DATABASE_URL="postgresql+asyncpg://user:password@localhost:5432/temis" diff --git a/backend/app/core/config.py b/backend/app/core/config.py index e11676c..69b5bdc 100644 --- a/backend/app/core/config.py +++ b/backend/app/core/config.py @@ -5,6 +5,7 @@ class Settings(BaseSettings): app_name: str = "Temis RiskControl API" app_version: str = "0.1.0" debug: bool = False + database_url: str = "sqlite+aiosqlite:///./temis.db" model_config = SettingsConfigDict(env_file=".env", env_file_encoding="utf-8") diff --git a/backend/app/main.py b/backend/app/main.py index d300f9f..454287a 100644 --- a/backend/app/main.py +++ b/backend/app/main.py @@ -1,9 +1,27 @@ +from contextlib import asynccontextmanager +from collections.abc import AsyncGenerator + from fastapi import FastAPI from app.api.router import api_router from app.core.config import settings +from app.database.base import Base +from app.database.session import engine + + +@asynccontextmanager +async def lifespan(application: FastAPI) -> AsyncGenerator[None, None]: + async with engine.begin() as conn: + await conn.run_sync(Base.metadata.create_all) + yield + -app = FastAPI(title=settings.app_name, version=settings.app_version, debug=settings.debug) +app = FastAPI( + title=settings.app_name, + version=settings.app_version, + debug=settings.debug, + lifespan=lifespan, +) app.include_router(api_router) diff --git a/backend/requirements.txt b/backend/requirements.txt index dad5104..4b0bc49 100644 --- a/backend/requirements.txt +++ b/backend/requirements.txt @@ -1,3 +1,10 @@ fastapi==0.115.12 uvicorn[standard]==0.34.0 pydantic-settings==2.8.1 +pydantic[email]==2.11.3 +sqlalchemy[asyncio]==2.0.40 +asyncpg==0.30.0 +aiosqlite==0.20.0 +pytest==8.3.5 +pytest-asyncio==0.24.0 +httpx==0.28.1 diff --git a/docs/database-design.pdf b/docs/database-design.pdf index 47fb84f..5d594c6 100644 Binary files a/docs/database-design.pdf and b/docs/database-design.pdf differ