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
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:
@@ -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
|
||||||
_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
|
import re as _re
|
||||||
m = _re.search(r'(\d+)$', row['name'])
|
_num_map = {'1': '一', '2': '二', '3': '三', '4': '四', '5': '五', '6': '六', '7': '七', '8': '八', '9': '九'}
|
||||||
|
_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:
|
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]
|
||||||
|
|||||||
Reference in New Issue
Block a user