修改过时文档,优化文档内容
This commit is contained in:
@@ -13,7 +13,7 @@
|
||||
|
||||
## 概要执行步骤(What / High level)
|
||||
1. 立刻移除前端的 `service_role`,前端只用 `anon`(阻断最大风险)。
|
||||
2. 实现最小后台 API(先做配送接单/状态流转 rpc + HTTP 接口)。
|
||||
2. 实现最小后台 API(订单管理、核心状态流转 rpc + HTTP 接口)。
|
||||
3. 在数据库添加约束、RLS 策略与 RPC(把关键状态流转做成原子函数)。
|
||||
4. 前端分阶段切换到新 API 并回归测试。
|
||||
5. 补充审计、幂等与监控,逐步迁移其它敏感写入。
|
||||
@@ -64,11 +64,11 @@ BEGIN
|
||||
VALUES (p_action_id, now())
|
||||
ON CONFLICT (action_id) DO NOTHING;
|
||||
|
||||
-- 执行原子更新:仅当 task 可被领取(status=1 且 driver_id IS NULL)
|
||||
-- 执行原子更新
|
||||
WITH u AS (
|
||||
UPDATE ml_delivery_tasks
|
||||
SET driver_id = p_driver_uuid, status = 2, updated_at = now()
|
||||
WHERE id = p_task_uuid AND status = 1 AND driver_id IS NULL
|
||||
UPDATE ml_orders
|
||||
SET status = 2, updated_at = now()
|
||||
WHERE id = p_task_uuid AND status = 1
|
||||
RETURNING *
|
||||
)
|
||||
SELECT * INTO v_task FROM u LIMIT 1;
|
||||
@@ -79,7 +79,7 @@ BEGIN
|
||||
|
||||
-- 写审计
|
||||
INSERT INTO audit_logs(actor_id, action, target_table, target_id, payload, created_at)
|
||||
VALUES (p_driver_uuid, 'accept_task', 'ml_delivery_tasks', p_task_uuid, row_to_json(v_task), now());
|
||||
VALUES (p_driver_uuid, 'accept_task', 'ml_orders', p_task_uuid, row_to_json(v_task), now());
|
||||
|
||||
RETURN jsonb_build_object('ok', true, 'task', to_jsonb(v_task));
|
||||
END;
|
||||
@@ -99,8 +99,8 @@ CREATE POLICY user_owns_address ON user_addresses
|
||||
USING (auth.uid() = user_id)
|
||||
WITH CHECK (auth.uid() = user_id);
|
||||
```
|
||||
- 对关键表(`ml_delivery_tasks`、`ml_orders`):
|
||||
- 禁止直接由匿名或普通前端更新关键列(例如 driver_id、status);只允许 `rpc` / service 调用通过函数更新。
|
||||
- 对关键表(如 `ml_orders`):
|
||||
- 禁止直接由匿名或普通前端更新关键列;只允许 `rpc` / service 调用通过函数更新。
|
||||
- 索引/约束:
|
||||
- message_id 唯一:`CREATE UNIQUE INDEX ux_express_notifications_message_id ON express_notifications(message_id);`
|
||||
- 补全 NOT NULL / FK / CHECK(枚举字段限制等)。
|
||||
@@ -131,7 +131,7 @@ CREATE POLICY user_owns_address ON user_addresses
|
||||
- [ ] 注释/移除前端 `service_role`:`ak/config.uts`(紧急)
|
||||
- [ ] 在 `server/` 新增 `POST /api/v1/delivery/accept-task`(鉴权 + 调用 RPC)
|
||||
- [ ] 在 DB 创建 `rpc_accept_task`、`action_dedupe`、`audit_logs` 表
|
||||
- [ ] 对 `user_addresses`、`ml_delivery_tasks`、`ml_orders` 等启用 RLS 策略(逐表)
|
||||
- [ ] 对 `user_addresses`、`ml_orders` 等启用 RLS 策略(逐表)
|
||||
- [ ] 前端将接单/确认调用迁移到新 API(feature-flag)并回归测试
|
||||
- [ ] 部署后监控并逐步扩大灰度
|
||||
|
||||
|
||||
Reference in New Issue
Block a user