fix: 配方编号迁移避免重复(一),自动分配下一个可用编号
All checks were successful
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 5s
PR Preview / deploy-preview (pull_request) Successful in 8s
Test / e2e-test (push) Successful in 2m55s

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-13 23:36:41 +00:00
parent 16b7d15981
commit 7be167deeb

View File

@@ -298,18 +298,23 @@ def init_db():
name = name[:m2.start()] + '' + m2.group(1) + '' name = name[:m2.start()] + '' + m2.group(1) + ''
c.execute("UPDATE recipes SET name = ? WHERE id = ?", (name, row['id'])) 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() _all_recipes2 = c.execute("SELECT id, name FROM recipes").fetchall()
_cn_nums = list('一二三四五六七八九十')
_base_groups = {} _base_groups = {}
for row in _all_recipes2: for row in _all_recipes2:
name = row['name'] name = row['name']
m = _re.match(r'^(.+?)[一二三四五六七八九十]+$', name) m = _re.match(r'^(.+?)([一二三四五六七八九十]+)$', name)
if m: if m:
_base_groups.setdefault(m.group(1), []).append(row['id']) _base_groups.setdefault(m.group(1), set()).add(m.group(2))
# Find bare names that match a numbered group # Find bare names that match a numbered group, assign next available number
for row in _all_recipes2: for row in _all_recipes2:
if row['name'] in _base_groups: 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 # 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]