Files
shutiaozhao127-boop cfdeeb5e41 chore: 初始化项目结构并添加基础配置文件
添加后端API和前端项目的初始目录结构,包括应用层模块、工具模块和模型定义
配置前后端的.dockerignore文件以排除开发环境文件
添加前端样式文件,包括字体、Tailwind CSS和主题配置
初始化Python虚拟环境中的类型标记文件
2026-04-01 16:55:24 +08:00

39 lines
1.2 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import os
import certifi
from beanie import init_beanie
from app.config import settings
from app.models.user import User
from app.models.report import Report
from app.models.analysis import Analysis
from app.models.chat import ChatSession
from app.models.checkup import CheckupPlan
async def init_db():
use_mock = os.environ.get("USE_MONGOMOCK", "").lower() in ("1", "true", "yes")
if use_mock:
# 使用 mongomock 内存数据库(无需安装 MongoDB)
from mongomock_motor import AsyncMongoMockClient
client = AsyncMongoMockClient()
else:
from motor.motor_asyncio import AsyncIOMotorClient
# Only use TLS for Atlas (mongodb+srv://) connections
if settings.mongodb_url.startswith("mongodb+srv://") or "mongodb.net" in settings.mongodb_url:
client = AsyncIOMotorClient(settings.mongodb_url, tlsCAFile=certifi.where())
else:
client = AsyncIOMotorClient(settings.mongodb_url)
await init_beanie(
database=client[settings.mongodb_db_name],
document_models=[
User,
Report,
Analysis,
ChatSession,
CheckupPlan,
],
)