29 lines
1.6 KiB
Markdown
29 lines
1.6 KiB
Markdown
### 1. 下单备份管理回退订单后未回到待下单管理
|
||
|
||
**旭东 → OpenClaw:**
|
||
> 发现一个异常,从下单备份管理里面回退订单的时候,订单没有回退到待下单管理中
|
||
|
||
**OpenClaw 响应:**
|
||
已定位并修复。
|
||
|
||
**根因:**
|
||
`pending_orders` 表存在唯一索引 `uk_product_code (product_code)`,但回退订单的设计是「保留原下单行为历史备份(rolled_back)+ 复制一条新 pending 记录」,需要同一商品存在多行。唯一索引导致回退时 INSERT 新 pending 行触发唯一约束冲突,订单已删除但待下单记录未生成。
|
||
|
||
错误日志铁证:
|
||
```
|
||
pymysql.err.IntegrityError: (1062, "Duplicate entry '【SEDATE】FSS7482' for key 'pending_orders.uk_product_code'")
|
||
pymysql.err.IntegrityError: (1062, "Duplicate entry 'JWTBS-RY-5575-ALJK' for key 'pending_orders.uk_product_code'")
|
||
```
|
||
|
||
**修复内容:**
|
||
1. `pending_orders` 移除 `uk_product_code` 唯一索引,改为普通索引 `idx_product_code`,支持同一商品多次下单历史
|
||
2. `migrate_db.py` 增加自动迁移:检测并移除唯一索引、补建普通索引
|
||
3. `add_pending` 更新逻辑改为按 `status='pending'` 行的 id 更新,不再依赖唯一索引的 `ON DUPLICATE KEY UPDATE`
|
||
4. 修复被卡住的两条 rolled_back 记录(JWTBS-RY-5575-ALJK、【SEDATE】FSS7482),补建 pending 待下单行
|
||
|
||
**验证:**
|
||
- 迁移执行成功(移除唯一索引、新增普通索引)
|
||
- 两条记录已补建 pending 行(id 899、900)
|
||
- 测试服务重启 HTTP 200
|
||
- Git 提交 8e88989(routes/purchase.py + migrate_db.py)
|