feat: 切换数据库至 PostgreSQL、支持环境变量

未来计划支持多种数据库,从 PostgreSQL 开始!
支持从环境变量读取启动设置,添加 nyahome env 命令用来持久化环境变量。

BREAKING CHANGE: 切换开发阶段的数据库,从 SQLite 到 PostgreSQL。
This commit is contained in:
2026-05-28 16:12:35 +08:00
parent 21cb4ee8c1
commit d62a9d9304
7 changed files with 155 additions and 13 deletions
+2
View File
@@ -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())