From 7e793dd8199d6d5bbc5c571fe929bd354dc8f711 Mon Sep 17 00:00:00 2001 From: DankerMu Date: Sat, 21 Feb 2026 18:21:21 +0800 Subject: [PATCH] fix(db): auto-migrate scene_card_json column for existing databases create_all does not ALTER existing tables. Add lightweight column migration in lifespan to add scene_card_json if missing. Co-Authored-By: Claude Opus 4.6 --- backend/app/main.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/backend/app/main.py b/backend/app/main.py index 9a28eb8..b3963c3 100644 --- a/backend/app/main.py +++ b/backend/app/main.py @@ -17,11 +17,23 @@ async def lifespan(app: FastAPI): import os + from sqlalchemy import text + from app.core.database import Base, engine os.makedirs("data", exist_ok=True) async with engine.begin() as conn: await conn.run_sync(Base.metadata.create_all) + # Lightweight column migrations for existing tables + for table, column, col_type in [ + ("scenes", "scene_card_json", "TEXT"), + ]: + try: + await conn.execute( + text(f"ALTER TABLE {table} ADD COLUMN {column} {col_type}") + ) + except Exception: + pass # Column already exists yield