feat: 切换数据库至 PostgreSQL、支持环境变量
未来计划支持多种数据库,从 PostgreSQL 开始! 支持从环境变量读取启动设置,添加 nyahome env 命令用来持久化环境变量。 BREAKING CHANGE: 切换开发阶段的数据库,从 SQLite 到 PostgreSQL。
This commit is contained in:
@@ -5,6 +5,7 @@ from contextlib import asynccontextmanager
|
||||
from pathlib import Path
|
||||
from typing import Any, AsyncGenerator
|
||||
|
||||
from dotenv import load_dotenv
|
||||
from fastapi import FastAPI
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
@@ -21,6 +22,7 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
@asynccontextmanager
|
||||
async def lifespan(app_: FastAPI) -> AsyncGenerator[None, Any]:
|
||||
load_dotenv(Path.cwd() / ".nyahome" / ".env")
|
||||
logger.info("🚀 服务启动中...")
|
||||
create_db()
|
||||
await asyncio.gather(init_admin_user(), config_manager.async_load_config())
|
||||
|
||||
Reference in New Issue
Block a user