From 7be167deebfcedbab10cbc5144e6586fc160a5b7 Mon Sep 17 00:00:00 2001 From: Hera Zhao Date: Mon, 13 Apr 2026 23:36:41 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20=E9=85=8D=E6=96=B9=E7=BC=96=E5=8F=B7?= =?UTF-8?q?=E8=BF=81=E7=A7=BB=E9=81=BF=E5=85=8D=E9=87=8D=E5=A4=8D=EF=BC=88?= =?UTF-8?q?=E4=B8=80=EF=BC=89=EF=BC=8C=E8=87=AA=E5=8A=A8=E5=88=86=E9=85=8D?= =?UTF-8?q?=E4=B8=8B=E4=B8=80=E4=B8=AA=E5=8F=AF=E7=94=A8=E7=BC=96=E5=8F=B7?= 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 | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/backend/database.py b/backend/database.py index c816ae2..e355710 100644 --- a/backend/database.py +++ b/backend/database.py @@ -298,18 +298,23 @@ def init_db(): 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 + # Migration: add number suffix to base recipes that have numbered siblings _all_recipes2 = c.execute("SELECT id, name FROM recipes").fetchall() + _cn_nums = list('一二三四五六七八九十') _base_groups = {} for row in _all_recipes2: name = row['name'] - m = _re.match(r'^(.+?)([一二三四五六七八九十]+)$', 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 + _base_groups.setdefault(m.group(1), set()).add(m.group(2)) + # Find bare names that match a numbered group, assign next available number for row in _all_recipes2: if row['name'] in _base_groups: - c.execute("UPDATE recipes SET name = ? WHERE id = ?", (row['name'] + '(一)', row['id'])) + used = _base_groups[row['name']] + next_num = next((n for n in _cn_nums if n not in used), '十') + new_name = row['name'] + '(' + next_num + ')' + c.execute("UPDATE recipes SET name = ? WHERE id = ?", (new_name, row['id'])) + _base_groups[row['name']].add(next_num) # Seed admin user if no users exist count = c.execute("SELECT COUNT(*) FROM users").fetchone()[0]