From 9562cbfe25398efb6dff85bc43208184142b8e4b Mon Sep 17 00:00:00 2001 From: Hera Zhao Date: Mon, 13 Apr 2026 23:05:57 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=B2=B9=E5=90=8D=E8=BF=81=E7=A7=BB?= =?UTF-8?q?=E5=A4=84=E7=90=86=E6=96=B0=E6=97=A7=E5=90=8D=E5=AD=97=E5=90=8C?= =?UTF-8?q?=E6=97=B6=E5=AD=98=E5=9C=A8=E7=9A=84=E6=83=85=E5=86=B5=EF=BC=8C?= =?UTF-8?q?=E9=81=BF=E5=85=8DUNIQUE=E5=86=B2=E7=AA=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 4.6 (1M context) --- backend/database.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/backend/database.py b/backend/database.py index 6164c08..ed862b8 100644 --- a/backend/database.py +++ b/backend/database.py @@ -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))