docs(database): 新建 docs/database 表文档 — 13 张表全量 + 索引
按"一表一文件"建库表文档(协作规范第 11 条):字段(类型/约束/默认)+ 索引与约束 + 关系 + 说明,从 model 的 Mapped 定义扒准。 - README 索引:13 张表总览 + 通用约定(主键/外键/金额分/北京时间日期串/JSONB variant) - 覆盖 user / coin_account / coin_transaction / cash_transaction / withdraw_order / signin_record / user_task / savings_record / ad_reward_record / ad_ecpm_record / feedback / comparison_record / comparison_milestone_claim - savings_record 文档强调"成交省钱"≠"比价行为",与 comparison_record 互不喂数据 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
# user_task — 一次性任务领取去重
|
||||
|
||||
> 模型 `app/models/task.py` | 关联接口 [tasks-list](../api/tasks-list.md) / [tasks-claim](../api/tasks-claim.md) | [← 表索引](./README.md)
|
||||
|
||||
像"打开消息提醒"这类只能领一次的任务,完成后写一行,`(user_id, task_key)` 唯一防重复领奖。可循环领取的任务(签到)不走这张表,有专表 `signin_record`。
|
||||
|
||||
## 字段
|
||||
| 列 | 类型 | 约束 / 默认 | 说明 |
|
||||
|---|---|---|---|
|
||||
| `id` | Integer | PK, autoincrement | |
|
||||
| `user_id` | Integer | FK→user.id, index, NOT NULL | 归属用户 |
|
||||
| `task_key` | String(48) | NOT NULL | 任务标识,见 `rewards.TASK_REWARDS`(如 `enable_notification`) |
|
||||
| `status` | String(16) | NOT NULL, default `completed` | 任务状态 |
|
||||
| `coin_awarded` | Integer | NOT NULL, default 0 | 该任务发放金币 |
|
||||
| `completed_at` | DateTime(tz) | server_default now() | 完成/领取时间 |
|
||||
|
||||
## 索引与约束
|
||||
- PK: `id`;index: `user_id`
|
||||
- UNIQUE(`user_id`, `task_key`) = `uq_task_user_key`(防重复领)
|
||||
|
||||
## 关系
|
||||
- `user_id` → `user.id`(多对一)
|
||||
|
||||
## 说明
|
||||
- 领取:写本表 + `grant_coins(biz_type='task_<key>', ref_id=task_key)` 同事务;重复领抛 409,未知 key 抛 404。
|
||||
- 比价战绩里程碑虽是"领一次"模型但**不复用本表**,另有 `comparison_milestone_claim`(因 task_key 是固定字典,里程碑是按次数解锁的序号)。
|
||||
Reference in New Issue
Block a user