From 2abd6563c7bb98f0481e3d1696ac9f66a9a57125 Mon Sep 17 00:00:00 2001 From: Hera Zhao Date: Mon, 13 Apr 2026 23:31:45 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20=E9=85=8D=E6=96=B9=E5=90=8D=E6=95=B0?= =?UTF-8?q?=E5=AD=97=E5=8A=A0=E6=8B=AC=E5=8F=B7=EF=BC=8C=E6=97=A0=E7=BC=96?= =?UTF-8?q?=E5=8F=B7=E7=9A=84=E5=90=8C=E7=B3=BB=E5=88=97=E9=85=8D=E6=96=B9?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E8=A1=A5=EF=BC=88=E4=B8=80=EF=BC=89?= 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 | 39 +++++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/backend/database.py b/backend/database.py index 187fe1f..c816ae2 100644 --- a/backend/database.py +++ b/backend/database.py @@ -275,22 +275,41 @@ def init_db(): "8、循环系统细胞律动": "细胞律动-循环系统", "9、内分泌系统细胞律动": "细胞律动-内分泌系统", "12、芳香调理技术": "芳香调理技术", - "普拉提根基配方:2": "普拉提根基配方二", + "普拉提根基配方:2": "普拉提根基配方(二)", } for old_name, new_name in _recipe_renames.items(): 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': '九'} - _trailing_num_recipes = c.execute("SELECT id, name FROM recipes").fetchall() - for row in _trailing_num_recipes: - import re as _re - m = _re.search(r'(\d+)$', row['name']) + _all_recipes = c.execute("SELECT id, name FROM recipes").fetchall() + for row in _all_recipes: + name = row['name'] + # Step 1: trailing Arabic digits → Chinese in parentheses: 灰指甲1 → 灰指甲(一) + m = _re.search(r'(\d+)$', name) if m: - digits = m.group(1) - chinese = ''.join(_num_map.get(d, d) for d in digits) - new_name = row['name'][:m.start()] + chinese - c.execute("UPDATE recipes SET name = ? WHERE id = ?", (new_name, row['id'])) + chinese = ''.join(_num_map.get(d, d) for d in m.group(1)) + name = name[:m.start()] + '(' + chinese + ')' + c.execute("UPDATE recipes SET name = ? WHERE id = ?", (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 count = c.execute("SELECT COUNT(*) FROM users").fetchone()[0]