fix: 配方名数字加括号,无编号的同系列配方自动补(一)
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 3s
PR Preview / test (pull_request) Successful in 5s
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:
2026-04-13 23:31:45 +00:00
parent 86ce634c71
commit 2abd6563c7

View File

@@ -275,22 +275,41 @@ def init_db():
"8、循环系统细胞律动": "细胞律动-循环系统", "8、循环系统细胞律动": "细胞律动-循环系统",
"9、内分泌系统细胞律动": "细胞律动-内分泌系统", "9、内分泌系统细胞律动": "细胞律动-内分泌系统",
"12、芳香调理技术": "芳香调理技术", "12、芳香调理技术": "芳香调理技术",
"普拉提根基配方2": "普拉提根基配方", "普拉提根基配方2": "普拉提根基配方(二)",
} }
for old_name, new_name in _recipe_renames.items(): for old_name, new_name in _recipe_renames.items():
c.execute("UPDATE recipes SET name = ? WHERE name = ?", (new_name, old_name)) c.execute("UPDATE recipes SET name = ? WHERE name = ?", (new_name, old_name))
# Migration: trailing Arabic numerals → Chinese numerals in recipe names # Migration: trailing Arabic numerals → Chinese numerals in parentheses
import re as _re
_num_map = {'1': '', '2': '', '3': '', '4': '', '5': '', '6': '', '7': '', '8': '', '9': ''} _num_map = {'1': '', '2': '', '3': '', '4': '', '5': '', '6': '', '7': '', '8': '', '9': ''}
_trailing_num_recipes = c.execute("SELECT id, name FROM recipes").fetchall() _all_recipes = c.execute("SELECT id, name FROM recipes").fetchall()
for row in _trailing_num_recipes: for row in _all_recipes:
import re as _re name = row['name']
m = _re.search(r'(\d+)$', row['name']) # Step 1: trailing Arabic digits → Chinese in parentheses: 灰指甲1 → 灰指甲(一)
m = _re.search(r'(\d+)$', name)
if m: if m:
digits = m.group(1) chinese = ''.join(_num_map.get(d, d) for d in m.group(1))
chinese = ''.join(_num_map.get(d, d) for d in digits) name = name[:m.start()] + '' + chinese + ''
new_name = row['name'][:m.start()] + chinese c.execute("UPDATE recipes SET name = ? WHERE id = ?", (name, row['id']))
c.execute("UPDATE recipes SET name = ? WHERE id = ?", (new_name, row['id'])) # Step 2: trailing bare Chinese numeral → add parentheses: 灰指甲一 → 灰指甲(一)
m2 = _re.search(r'([一二三四五六七八九十]+)$', name)
if m2 and not name.endswith(''):
name = name[:m2.start()] + '' + m2.group(1) + ''
c.execute("UPDATE recipes SET name = ? WHERE id = ?", (name, row['id']))
# Migration: add (一) to base recipes that have numbered siblings
_all_recipes2 = c.execute("SELECT id, name FROM recipes").fetchall()
_base_groups = {}
for row in _all_recipes2:
name = row['name']
m = _re.match(r'^(.+?)[一二三四五六七八九十]+$', name)
if m:
_base_groups.setdefault(m.group(1), []).append(row['id'])
# Find bare names that match a numbered group
for row in _all_recipes2:
if row['name'] in _base_groups:
c.execute("UPDATE recipes SET name = ? WHERE id = ?", (row['name'] + '(一)', row['id']))
# Seed admin user if no users exist # Seed admin user if no users exist
count = c.execute("SELECT COUNT(*) FROM users").fetchone()[0] count = c.execute("SELECT COUNT(*) FROM users").fetchone()[0]