Files
QingTianJiZhang/DATA_DESIGN.md

64 lines
2.0 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.

# 记账应用数据设计文档
本文档描述了本地存储的 SQLite 数据库结构,旨在方便后期迁移到后端数据库(如 MySQL/PostgreSQL
## 数据库概览
- **数据库名称**: `expense_tracker.db`
- **版本**: 2
## 表结构
### 1. Categories (分类表)
用于存储收支分类,支持多级分类(无限层级)。
| 字段名 | 类型 | 描述 | 备注 |
| :--- | :--- | :--- | :--- |
| `id` | INTEGER | 主键ID | 自增 |
| `name` | TEXT | 分类名称 | 例如:餐饮、交通 |
| `type` | TEXT | 类型 | 枚举值: `income`, `expense` |
| `icon` | TEXT | 图标标识 | Material Icon 的名称或代码 |
| `color` | INTEGER | 颜色值 | 存储 ARGB 的整数值 |
| `parentId` | INTEGER | 父分类ID | 外键关联 `Categories.id`,为空则为一级分类 |
**预设数据示例:**
```json
[
{ "id": 1, "name": "餐饮", "type": "expense", "icon": "restaurant", "color": 0xFFFF5722, "parentId": null },
{ "id": 2, "name": "交通", "type": "expense", "icon": "directions_bus", "color": 0xFF2196F3, "parentId": null },
{ "id": 8, "name": "早餐", "type": "expense", "icon": "breakfast_dining", "color": 0xFFFF5722, "parentId": 1 }
]
```
### 2. Transactions (交易记录表)
用于存储每一笔收支记录。
| 字段名 | 类型 | 描述 | 备注 |
| :--- | :--- | :--- | :--- |
| `id` | TEXT | 主键ID | UUID 格式,方便后期同步 |
| `amount` | REAL | 金额 | |
| `type` | TEXT | 类型 | `income`, `expense` |
| `categoryId` | INTEGER | 分类ID | 外键关联 `Categories.id` |
| `date` | INTEGER | 交易日期 | Unix 时间戳 (毫秒) |
| `note` | TEXT | 备注 | 可为空 |
| `createdAt` | INTEGER | 创建时间 | Unix 时间戳 (毫秒) |
| `updatedAt` | INTEGER | 更新时间 | Unix 时间戳 (毫秒) |
**数据示例:**
```json
{
"id": "550e8400-e29b-41d4-a716-446655440000",
"amount": 25.5,
"type": "expense",
"categoryId": 8,
"date": 1678886400000,
"note": "豆浆油条",
"createdAt": 1678886400000,
"updatedAt": 1678886400000
}
```