File tree Expand file tree Collapse file tree 2 files changed +8
-2
lines changed
Expand file tree Collapse file tree 2 files changed +8
-2
lines changed Original file line number Diff line number Diff line change @@ -22,12 +22,18 @@ async def lifespan(app: FastAPI):
2222 logger .info ("XCodeReviewer 后端服务启动中..." )
2323
2424 # 初始化数据库(创建默认账户)
25+ # 注意:需要先运行 alembic upgrade head 创建表结构
2526 try :
2627 async with AsyncSessionLocal () as db :
2728 await init_db (db )
2829 logger .info ("✓ 数据库初始化完成" )
2930 except Exception as e :
30- logger .warning (f"数据库初始化跳过(可能数据库未就绪): { e } " )
31+ # 表不存在时静默跳过,等待用户运行数据库迁移
32+ error_msg = str (e )
33+ if "does not exist" in error_msg or "UndefinedTableError" in error_msg :
34+ logger .info ("数据库表未创建,请先运行: alembic upgrade head" )
35+ else :
36+ logger .warning (f"数据库初始化跳过: { e } " )
3137
3238 logger .info ("=" * 50 )
3339 logger .info ("XCodeReviewer 后端服务已启动" )
Original file line number Diff line number Diff line change @@ -32,7 +32,7 @@ services:
3232 depends_on :
3333 db :
3434 condition : service_healthy
35- command : uvicorn app.main:app --host 0.0.0.0 --port 8000 --reload
35+ command : sh -c "alembic upgrade head && uvicorn app.main:app --host 0.0.0.0 --port 8000 --reload"
3636 networks :
3737 - xcodereviewer-network
3838
You can’t perform that action at this time.
0 commit comments