feat: track designer downloads and notifications
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
from fastapi import FastAPI, Request, Response
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
from sqlalchemy import inspect, text
|
||||
from app.core.config import settings
|
||||
from app.core.database import Base, engine
|
||||
from app.api import auth, works, orders, payment, upload
|
||||
@@ -8,6 +9,25 @@ from app.api import auth, works, orders, payment, upload
|
||||
# 创建数据库表
|
||||
Base.metadata.create_all(bind=engine)
|
||||
|
||||
|
||||
def ensure_runtime_schema():
|
||||
inspector = inspect(engine)
|
||||
columns = {col["name"] for col in inspector.get_columns("download_records")}
|
||||
statements = []
|
||||
if "designer_name" not in columns:
|
||||
statements.append("ALTER TABLE download_records ADD COLUMN designer_name VARCHAR(100)")
|
||||
if "work_title" not in columns:
|
||||
statements.append("ALTER TABLE download_records ADD COLUMN work_title VARCHAR(255)")
|
||||
if "amount" not in columns:
|
||||
statements.append("ALTER TABLE download_records ADD COLUMN amount FLOAT DEFAULT 0")
|
||||
if statements:
|
||||
with engine.begin() as conn:
|
||||
for sql in statements:
|
||||
conn.execute(text(sql))
|
||||
|
||||
|
||||
ensure_runtime_schema()
|
||||
|
||||
# 创建 FastAPI 应用
|
||||
app = FastAPI(
|
||||
title=settings.PROJECT_NAME,
|
||||
|
||||
Reference in New Issue
Block a user