fix: 精油编辑统一保存到 DB + 导出 Excel 增加功效列
Some checks failed
Test / unit-test (push) Successful in 7s
Test / build-check (push) Successful in 4s
PR Preview / teardown-preview (pull_request) Has been skipped
Test / e2e-test (push) Failing after 1m12s
PR Preview / test (pull_request) Successful in 7s
PR Preview / deploy-preview (pull_request) Successful in 19s
Some checks failed
Test / unit-test (push) Successful in 7s
Test / build-check (push) Successful in 4s
PR Preview / teardown-preview (pull_request) Has been skipped
Test / e2e-test (push) Failing after 1m12s
PR Preview / test (pull_request) Successful in 7s
PR Preview / deploy-preview (pull_request) Successful in 19s
- 新增 oil_cards 表,持久化知识卡片(功效/用法/方法/注意/emoji) - POST /api/oils 扩展接受 card_* 字段,在同一事务里 upsert oil_cards - GET /api/oil-cards 返回全部卡片 - 前端 getOilCard 优先查 DB,再 fallback 静态表 - saveEditOil 统一走 saveOil,不再分两套保存 - 精油价目 Excel 导出增加「功效」列 - 首次部署自动从静态 OIL_CARDS 播种到 oil_cards 表 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -123,6 +123,15 @@ def init_db():
|
||||
tag_name TEXT NOT NULL,
|
||||
sort_order INTEGER DEFAULT 0
|
||||
);
|
||||
CREATE TABLE IF NOT EXISTS oil_cards (
|
||||
name TEXT PRIMARY KEY REFERENCES oils(name) ON DELETE CASCADE,
|
||||
emoji TEXT DEFAULT '',
|
||||
en TEXT DEFAULT '',
|
||||
effects TEXT DEFAULT '',
|
||||
usage TEXT DEFAULT '',
|
||||
method TEXT DEFAULT '',
|
||||
caution TEXT DEFAULT ''
|
||||
);
|
||||
""")
|
||||
|
||||
# Migration: add password and brand fields to users if missing
|
||||
@@ -341,7 +350,7 @@ def log_audit(conn, user_id, action, target_type=None, target_id=None, target_na
|
||||
)
|
||||
|
||||
|
||||
def seed_defaults(default_oils_meta: dict, default_recipes: list):
|
||||
def seed_defaults(default_oils_meta: dict, default_recipes: list, default_oil_cards: dict = None):
|
||||
"""Seed DB with defaults if empty."""
|
||||
conn = get_db()
|
||||
c = conn.cursor()
|
||||
@@ -379,5 +388,18 @@ def seed_defaults(default_oils_meta: dict, default_recipes: list):
|
||||
(rid, tag),
|
||||
)
|
||||
|
||||
# Seed oil_cards from static data if table is empty
|
||||
if default_oil_cards:
|
||||
card_count = c.execute("SELECT COUNT(*) FROM oil_cards").fetchone()[0]
|
||||
if card_count == 0:
|
||||
for name, card in default_oil_cards.items():
|
||||
c.execute(
|
||||
"INSERT OR IGNORE INTO oil_cards (name, emoji, en, effects, usage, method, caution) "
|
||||
"VALUES (?, ?, ?, ?, ?, ?, ?)",
|
||||
(name, card.get("emoji", ""), card.get("en", ""),
|
||||
card.get("effects", ""), card.get("usage", ""),
|
||||
card.get("method", ""), card.get("caution", "")),
|
||||
)
|
||||
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
Reference in New Issue
Block a user