Implement Alembic for database migrations and update FastAPI initialization

- Integrate Alembic for managing database schema migrations, replacing the previous SQL schema management.
- Update the FastAPI application to synchronize interface definitions at startup.
- Modify the Docker Compose command to run Alembic migrations before starting the API.
- Enhance the Makefile with new commands for database migration and revision management.
- Remove outdated SQL schema and seed files, transitioning to a more dynamic migration approach.
- Add initial migration scripts and configuration for Alembic, ensuring a structured database evolution.
This commit is contained in:
Xin Wang
2026-07-09 16:29:10 +08:00
parent 54329aa516
commit 03b532dd09
16 changed files with 325 additions and 247 deletions

View File

@@ -1,4 +1,4 @@
"""FastAPI 入口。挂载路由,放行前端跨域,启动时建表
"""FastAPI 入口。挂载路由,放行前端跨域,启动时同步接口定义
启动: uv run --with-requirements requirements.txt uvicorn app:app --reload --port 8000
@@ -16,7 +16,7 @@ from contextlib import asynccontextmanager
import config
import uvicorn
from db.session import init_db
from db.session import sync_interface_definitions
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
@@ -33,7 +33,7 @@ from routes import (
@asynccontextmanager
async def lifespan(_app: FastAPI):
await init_db() # MVP:启动建表;表稳定后切 alembic
await sync_interface_definitions()
yield