fix: 油名迁移处理新旧名字同时存在的情况,避免UNIQUE冲突
Some checks failed
PR Preview / teardown-preview (pull_request) Has been skipped
Test / unit-test (push) Successful in 5s
Test / build-check (push) Successful in 4s
PR Preview / test (pull_request) Successful in 6s
PR Preview / deploy-preview (pull_request) Successful in 10s
Test / e2e-test (push) Has been cancelled
Some checks failed
PR Preview / teardown-preview (pull_request) Has been skipped
Test / unit-test (push) Successful in 5s
Test / build-check (push) Successful in 4s
PR Preview / test (pull_request) Successful in 6s
PR Preview / deploy-preview (pull_request) Successful in 10s
Test / e2e-test (push) Has been cancelled
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -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