clouddisk-project/architecture/database-schema.md

65 lines
1.8 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.

# 数据库 Schema 文档
## users 表
| 字段 | 类型 | 说明 |
|------|------|------|
| id | INTEGER | 主键,自增 |
| username | TEXT | 用户名,唯一 |
| password_hash | TEXT | 密码哈希 |
| email | TEXT | 邮箱 |
| storage_used | INTEGER | 已用存储(字节) |
| storage_limit | INTEGER | 存储上限(字节) |
| created_at | DATETIME | 创建时间 |
| updated_at | DATETIME | 更新时间 |
## files 表
| 字段 | 类型 | 说明 |
|------|------|------|
| id | INTEGER | 主键,自增 |
| user_id | INTEGER | 用户ID外键 |
| parent_id | INTEGER | 父文件夹ID |
| name | TEXT | 文件名 |
| type | TEXT | 文件类型 |
| size | INTEGER | 文件大小 |
| path | TEXT | 存储路径 |
| hash | TEXT | 文件哈希 |
| is_folder | INTEGER | 是否文件夹 |
| created_at | DATETIME | 创建时间 |
| updated_at | DATETIME | 更新时间 |
| deleted_at | DATETIME | 删除时间 |
## shares 表
| 字段 | 类型 | 说明 |
|------|------|------|
| id | INTEGER | 主键,自增 |
| file_id | INTEGER | 文件ID外键 |
| share_token | TEXT | 分享令牌,唯一 |
| password | TEXT | 访问密码 |
| expires_at | DATETIME | 过期时间 |
| view_count | INTEGER | 查看次数 |
| created_at | DATETIME | 创建时间 |
## sync_status 表
| 字段 | 类型 | 说明 |
|------|------|------|
| id | INTEGER | 主键,自增 |
| user_id | INTEGER | 用户ID外键 |
| last_sync_time | DATETIME | 最后同步时间 |
| status | TEXT | 状态 |
| total_files | INTEGER | 总文件数 |
| synced_files | INTEGER | 已同步文件数 |
## 索引
```sql
CREATE INDEX idx_files_user ON files(user_id);
CREATE INDEX idx_files_parent ON files(parent_id);
CREATE INDEX idx_files_hash ON files(hash);
CREATE INDEX idx_shares_token ON shares(share_token);
CREATE INDEX idx_sync_user ON sync_status(user_id);
```