mirror of
https://github.com/Cccc-owo/CheckInApp.git
synced 2026-06-17 14:06:28 +00:00
feat(backend): add automatic DB migrations
Add a lightweight migration runner with schema_migrations tracking, run pending migrations during backend startup before the scheduler, and keep a manual backend-migrate entrypoint. The change also moves the existing lockout and task-thread-ID schema steps into shared migration modules, updates docs, and archives the OpenSpec change.
This commit is contained in:
@@ -8,6 +8,7 @@ import logging
|
||||
from pathlib import Path
|
||||
|
||||
from backend.config import settings
|
||||
from backend.migrations import run_pending_migrations
|
||||
from backend.models import init_db
|
||||
from backend.exceptions import BaseAPIException
|
||||
from backend.schemas.response import ErrorResponse, ErrorDetail
|
||||
@@ -37,6 +38,14 @@ async def lifespan(app: FastAPI):
|
||||
init_db()
|
||||
logger.info("数据库初始化完成")
|
||||
|
||||
logger.info("正在执行数据库迁移...")
|
||||
migration_result = run_pending_migrations()
|
||||
logger.info(
|
||||
"数据库迁移完成:applied=%s skipped=%s",
|
||||
len(migration_result.applied),
|
||||
len(migration_result.skipped),
|
||||
)
|
||||
|
||||
# 确保必要的目录存在
|
||||
settings.SESSION_DIR.mkdir(parents=True, exist_ok=True)
|
||||
(settings.BASE_DIR / "data").mkdir(parents=True, exist_ok=True)
|
||||
|
||||
Reference in New Issue
Block a user