fix:优化项目内容
This commit is contained in:
@@ -32,27 +32,28 @@ def create_app() -> FastAPI:
|
||||
@app.on_event("startup")
|
||||
def on_startup() -> None:
|
||||
Base.metadata.create_all(bind=engine)
|
||||
# Add new columns to finance_records if they don't exist (Module 6)
|
||||
# Lightweight schema migrations for SQLite (add columns if missing)
|
||||
try:
|
||||
from sqlalchemy import text
|
||||
with engine.connect() as conn:
|
||||
# finance_records: amount, billing_date
|
||||
r = conn.execute(text("PRAGMA table_info(finance_records)"))
|
||||
cols = [row[1] for row in r]
|
||||
if "amount" not in cols:
|
||||
conn.execute(text("ALTER TABLE finance_records ADD COLUMN amount NUMERIC(12,2)"))
|
||||
if "billing_date" not in cols:
|
||||
conn.execute(text("ALTER TABLE finance_records ADD COLUMN billing_date DATE"))
|
||||
conn.commit()
|
||||
except Exception:
|
||||
pass
|
||||
# Add customers.tags if missing (customer tags for project 收纳)
|
||||
try:
|
||||
from sqlalchemy import text
|
||||
with engine.connect() as conn:
|
||||
if "tags" not in cols:
|
||||
conn.execute(text("ALTER TABLE finance_records ADD COLUMN tags VARCHAR(512)"))
|
||||
if "meta_json" not in cols:
|
||||
conn.execute(text("ALTER TABLE finance_records ADD COLUMN meta_json TEXT"))
|
||||
|
||||
# customers: tags
|
||||
r = conn.execute(text("PRAGMA table_info(customers)"))
|
||||
cols = [row[1] for row in r]
|
||||
if "tags" not in cols:
|
||||
conn.execute(text("ALTER TABLE customers ADD COLUMN tags VARCHAR(512)"))
|
||||
|
||||
conn.commit()
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user