feat: 套装方案对比与导出功能 #32
@@ -254,8 +254,13 @@ def init_db():
|
||||
# Migration: rename oils 西洋蓍草→西洋蓍草石榴籽, 元气→元气焕能
|
||||
_oil_renames = [("西洋蓍草", "西洋蓍草石榴籽"), ("元气", "元气焕能")]
|
||||
for old_name, new_name in _oil_renames:
|
||||
exists = c.execute("SELECT 1 FROM oils WHERE name = ?", (old_name,)).fetchone()
|
||||
if exists:
|
||||
old_exists = c.execute("SELECT 1 FROM oils WHERE name = ?", (old_name,)).fetchone()
|
||||
new_exists = c.execute("SELECT 1 FROM oils WHERE name = ?", (new_name,)).fetchone()
|
||||
if old_exists and new_exists:
|
||||
# Both exist: delete old, update recipe references to new
|
||||
c.execute("DELETE FROM oils WHERE name = ?", (old_name,))
|
||||
c.execute("UPDATE recipe_ingredients SET oil_name = ? WHERE oil_name = ?", (new_name, old_name))
|
||||
elif old_exists:
|
||||
c.execute("UPDATE oils SET name = ? WHERE name = ?", (new_name, old_name))
|
||||
c.execute("UPDATE recipe_ingredients SET oil_name = ? WHERE oil_name = ?", (new_name, old_name))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user