Files
life-echo/docs/数据库设计.md

124 lines
2.9 KiB
Markdown
Raw Normal View History

2026-01-07 11:57:17 +08:00
# 数据库设计文档
## Android 本地数据库Room
### User 表
```kotlin
@Entity(tableName = "users")
data class User(
@PrimaryKey val id: String,
val nickname: String,
val avatarUrl: String?,
val subscriptionType: String, // free, premium
val createdAt: Long
)
```
### Conversation 表
```kotlin
@Entity(tableName = "conversations")
data class Conversation(
@PrimaryKey val id: String,
val userId: String,
val startedAt: Long,
val endedAt: Long?,
val durationSeconds: Int,
val summary: String?,
val currentTopic: String?, // 当前话题
val conversationStage: String? // CHILDHOOD, EDUCATION, CAREER, FAMILY, BELIEFS, SUMMARY
)
```
### ConversationSegment 表
```kotlin
@Entity(tableName = "conversation_segments")
data class ConversationSegment(
@PrimaryKey val id: String,
val conversationId: String,
val audioPath: String?,
val transcriptText: String,
val createdAt: Long,
val processed: Boolean,
val topicCategory: String? // 话题分类
)
```
### Chapter 表
```kotlin
@Entity(tableName = "chapters")
data class Chapter(
@PrimaryKey val id: String,
val title: String,
val content: String,
val orderIndex: Int,
val status: String, // draft, completed
val updatedAt: Long,
val category: String // 章节分类
)
```
### Book 表
```kotlin
@Entity(tableName = "books")
data class Book(
@PrimaryKey val id: String,
val userId: String,
val title: String,
val totalPages: Int,
val totalWords: Int,
val updatedAt: Long
)
```
## 后端数据库SQLAlchemy
### users 表
- id (String, Primary Key)
- openid (String, Unique) - 微信 OpenID
- nickname (String)
- avatar_url (String, Nullable)
- subscription_type (String) - free, premium
- created_at (DateTime)
### conversations 表
- id (String, Primary Key)
- user_id (String, Foreign Key -> users.id)
- started_at (DateTime)
- ended_at (DateTime, Nullable)
- duration_seconds (Integer)
- summary (String, Nullable)
- status (String) - active, ended, processing
- current_topic (String, Nullable)
- conversation_stage (String, Nullable) - childhood, education, career, family, beliefs, summary
### segments 表
- id (String, Primary Key)
- conversation_id (String, Foreign Key -> conversations.id)
- audio_url (String, Nullable)
- transcript_text (Text)
- created_at (DateTime)
- processed (Boolean, Default False)
- topic_category (String, Nullable)
- agent_response (Text, Nullable)
### chapters 表
- id (String, Primary Key)
- user_id (String, Foreign Key -> users.id)
- title (String)
- content (Text)
- order_index (Integer)
- status (String) - draft, completed
- images (JSON, Nullable) - 图片 URL 列表
- updated_at (DateTime)
- category (String) - 章节分类
### books 表
- id (String, Primary Key)
- user_id (String, Foreign Key -> users.id)
- title (String)
- total_pages (Integer)
- total_words (Integer)
- cover_image_url (String, Nullable)
- updated_at (DateTime)