Files
Neo-ZQYY/docs/database/BD_manual_auth_users_avatar.md
Neo 70324d8542 chore: 文档与 IDE 配置整理
- .kiro/specs/ → docs/specs/(41 个历史需求 spec 迁移,移除 .config.kiro)
- CLAUDE.md 三层拆分:根文件精简 + apps/backend/CLAUDE.md + .claude/commands/
- 新增 /spec-close、/pre-change 两个工作流命令
- DDL 基线刷新(从测试库重新导出 11 个文件,dws 35→38 表,biz 18→21 表)
- BD_Manual → BD_manual 命名统一(48 个文件)
- 修复 3 处文档与数据库不一致(auth.users.status 默认值、scheduled_tasks 字段、RLS 视图数)
- 新增 BD_manual_public_rbac_tables.md(public schema 8 张 RBAC/工作流表)
- 合并 biz.trigger_jobs 文档(10→12 字段,归档独立文档)
- docs/database/README.md 索引更新

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-06 00:02:37 +08:00

54 lines
1.6 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# BD 手册auth.users.avatar_url 字段
## 概述
`auth.users` 表新增 `avatar_url` 字段,存储用户头像的相对路径。
## 字段定义
| 字段 | 类型 | 约束 | 说明 |
|------|------|------|------|
| `avatar_url` | `VARCHAR(500)` | `NULL` | 头像相对路径,格式 `avatars/{user_id}.jpg` |
## 数据流
1. 小程序端通过 `<button open-type="chooseAvatar">` 获取微信头像临时路径
2. 通过 `wx.uploadFile` 上传到 `POST /api/xcx/avatar/upload`
3. 后端保存文件到 `AVATAR_EXPORT_PATH/{user_id}.jpg`(覆盖式,幂等)
4. 数据库 `avatar_url` 更新为 `avatars/{user_id}.jpg`(相对路径)
5. 小程序通过 `GET /api/xcx/avatar/{user_id}` 获取头像文件
## 关联接口
| 接口 | 方法 | 说明 |
|------|------|------|
| `/api/xcx/avatar/upload` | POST | 上传头像,更新 avatar_url |
| `/api/xcx/avatar/{user_id}` | GET | 获取头像文件FileResponse |
| `/api/xcx/me` | GET | 返回 avatar_url 字段 |
## 设计决策
- 审核表 `auth.user_applications` 不冗余 `avatar_url`,通过 JOIN `auth.users` 获取(头像可能更新)
- 文件命名按 `user_id`,覆盖式保存(幂等,无历史版本)
- 文件大小限制 2MB空文件拒绝
## 迁移脚本
`db/zqyy_app/migrations/20260324_add_avatar_url_to_users.sql`
## 环境变量
`AVATAR_EXPORT_PATH` — 头像文件存储目录,缺失时后端报 500 错误
## 回滚
```sql
ALTER TABLE auth.users DROP COLUMN IF EXISTS avatar_url;
```
## 验证
```sql
SELECT id, avatar_url FROM auth.users WHERE avatar_url IS NOT NULL LIMIT 5;
```