Files
eryao/docs/references/old-database-schema.md
T

14 KiB

Old 项目数据库表结构参考

本文档记录 old 文件夹中历史项目的数据库表结构定义。


一、login-service (后端服务)

1. users - 用户表

字段 类型 约束 说明
id BIGINT PRIMARY KEY, AUTO_INCREMENT 主键ID
phone_number VARCHAR(20) UNIQUE, NOT NULL 手机号
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP 创建时间
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP 更新时间

索引:

  • idx_phone_number ON phone_number

2. verification_codes - 验证码表

字段 类型 约束 说明
id BIGINT PRIMARY KEY, AUTO_INCREMENT 主键ID
phone_number VARCHAR(20) NOT NULL 手机号
code VARCHAR(6) NOT NULL 验证码
expiration_time TIMESTAMP NOT NULL 过期时间
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP 创建时间

索引:

  • idx_vc_phone_number ON phone_number
  • idx_vc_expiration ON expiration_time

3. user_profile - 用户资料表

字段 类型 约束 说明
id BIGINT PRIMARY KEY, AUTO_INCREMENT 主键ID
phone_number VARCHAR(20) UNIQUE, NOT NULL 手机号
nickname VARCHAR(50) 昵称
avatar_url VARCHAR(500) 头像URL
signature VARCHAR(200) 个性签名
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP 创建时间
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP 更新时间

4. user_tokens - 用户令牌表

字段 类型 约束 说明
id BIGINT PRIMARY KEY, AUTO_INCREMENT 主键ID
user_id BIGINT NOT NULL 用户ID
token VARCHAR(255) NOT NULL 访问令牌
refresh_token VARCHAR(255) 刷新令牌
expires_at TIMESTAMP 过期时间
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP 创建时间

5. user_feedback - 用户反馈表

字段 类型 约束 说明
id BIGINT PRIMARY KEY, AUTO_INCREMENT 主键ID
user_id BIGINT NOT NULL 用户ID
content TEXT NOT NULL 反馈内容
contact VARCHAR(100) 联系方式
status VARCHAR(20) DEFAULT 'PENDING' 处理状态
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP 创建时间
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP 更新时间

6. user_coin - 用户金币表

字段 类型 约束 说明
id BIGINT PRIMARY KEY, AUTO_INCREMENT 主键ID
user_id BIGINT UNIQUE, NOT NULL 用户ID
coin_count BIGINT DEFAULT 0 金币数量
total_charged BIGINT DEFAULT 0 累计充值金币
total_consumed BIGINT DEFAULT 0 累计消费金币
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP 创建时间
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP 更新时间

7. notification - 通知表

字段 类型 约束 说明
id BIGINT PRIMARY KEY, AUTO_INCREMENT 主键ID
user_id BIGINT NOT NULL 用户ID
title VARCHAR(100) NOT NULL 通知标题
content TEXT 通知内容
type VARCHAR(20) 通知类型
is_read BOOLEAN DEFAULT FALSE 是否已读
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP 创建时间

8. payment_record - 支付记录表

字段 类型 约束 说明
id BIGINT PRIMARY KEY, AUTO_INCREMENT 主键ID
user_id BIGINT NOT NULL 用户ID
order_id VARCHAR(64) NOT NULL 订单ID
amount DECIMAL(10,2) NOT NULL 支付金额
coin_amount BIGINT NOT NULL 购买金币数量
payment_method VARCHAR(20) 支付方式
status VARCHAR(20) NOT NULL 支付状态
transaction_id VARCHAR(100) 第三方交易号
paid_at TIMESTAMP 支付时间
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP 创建时间

9. payment_order - 支付订单表

字段 类型 约束 说明
id BIGINT PRIMARY KEY, AUTO_INCREMENT 主键ID
order_no VARCHAR(64) UNIQUE, NOT NULL 订单号
user_id BIGINT NOT NULL 用户ID
product_id VARCHAR(50) NOT NULL 商品ID
product_name VARCHAR(100) NOT NULL 商品名称
amount DECIMAL(10,2) NOT NULL 订单金额
status VARCHAR(20) NOT NULL 订单状态
pay_url TEXT 支付链接
expire_time TIMESTAMP 过期时间
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP 创建时间
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP 更新时间

10. sensitive_word_violations - 敏感词违规记录表

字段 类型 约束 说明
id BIGINT PRIMARY KEY, AUTO_INCREMENT 主键ID
user_id BIGINT NOT NULL, FK 用户ID
content_type VARCHAR(20) NOT NULL 内容类型:NICKNAME, SIGNATURE
violation_type VARCHAR(30) NOT NULL 违规类型:POLITICAL, ILLEGAL, VULGAR, ADVERTISING, PERSONAL_ATTACK
detection_service VARCHAR(20) DEFAULT 'LOCAL' 检测服务类型:LOCAL, ALIYUN
risk_level VARCHAR(50) 阿里云风险等级
confidence DOUBLE 阿里云置信度(0-1)
original_content TEXT NOT NULL 原始内容
matched_words TEXT NOT NULL 匹配到的敏感词(JSON)
aliyun_response TEXT 阿里云完整响应
client_ip VARCHAR(45) 客户端IP
user_agent TEXT 用户代理
violation_time DATETIME NOT NULL 违规时间
created_at DATETIME DEFAULT CURRENT_TIMESTAMP 创建时间

索引:

  • idx_user_id ON user_id
  • idx_content_type ON content_type
  • idx_violation_type ON violation_type
  • idx_violation_time ON violation_time
  • idx_user_violation_time ON (user_id, violation_time)
  • idx_client_ip ON client_ip
  • idx_detection_service ON detection_service
  • idx_risk_level ON risk_level
  • idx_confidence ON confidence

外键:

  • user_id REFERENCES user_profile(id) ON DELETE CASCADE

11. user_divination_records - 用户解卦记录表

字段 类型 约束 说明
id BIGINT PRIMARY KEY, AUTO_INCREMENT 主键ID
user_id BIGINT NOT NULL 用户ID
trace_id VARCHAR(64) NOT NULL 请求追踪ID
question TEXT NOT NULL 用户问题
question_type VARCHAR(50) NOT NULL 问题类型
divination_data LONGTEXT NOT NULL 卦象详情JSON
deepseek_request LONGTEXT NOT NULL 发送给DeepSeek的请求JSON
deepseek_response LONGTEXT DeepSeek响应JSON
interpretation_result LONGTEXT 解卦结果文本
api_success BOOLEAN NOT NULL, DEFAULT FALSE API调用是否成功
error_message TEXT 错误信息
api_duration_ms BIGINT API调用耗时(毫秒)
phone_number VARCHAR(20) 用户手机号(冗余)
created_at DATETIME NOT NULL, DEFAULT CURRENT_TIMESTAMP 创建时间

索引:

  • idx_user_id ON user_id
  • idx_trace_id ON trace_id
  • idx_phone_number ON phone_number
  • idx_created_at ON created_at
  • idx_api_success ON api_success
  • idx_question_type ON question_type
  • idx_user_created ON (user_id, created_at)

12. user_divination_history - 用户卦象历史同步表

字段 类型 约束 说明
id BIGINT PRIMARY KEY, AUTO_INCREMENT 主键ID
user_id BIGINT NOT NULL, FK 用户ID
phone_number VARCHAR(20) NOT NULL 用户手机号
local_record_id BIGINT 本地记录ID
json_data LONGTEXT NOT NULL 卦象详情JSON
ai_result LONGTEXT NOT NULL AI解卦结果
question_type VARCHAR(50) NOT NULL 问题类型
question TEXT NOT NULL 用户问题
timestamp BIGINT NOT NULL 创建时间戳(毫秒)
is_active BOOLEAN NOT NULL, DEFAULT TRUE 是否有效
sync_time DATETIME NOT NULL, DEFAULT CURRENT_TIMESTAMP 同步时间
updated_at DATETIME NOT NULL, DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP 更新时间

索引:

  • idx_user_phone ON (user_id, phone_number)
  • idx_phone_active ON (phone_number, is_active)
  • idx_user_active_time ON (user_id, is_active, timestamp)
  • idx_local_record ON local_record_id
  • idx_sync_time ON sync_time
  • idx_question_type ON question_type

外键:

  • user_id REFERENCES user_profile(id)

13. network_access_logs - 网络访问日志表

字段 类型 约束 说明
id BIGINT PRIMARY KEY, AUTO_INCREMENT 主键ID
user_id BIGINT NULL 用户ID
phone_number VARCHAR(20) NULL 用户手机号
client_ip VARCHAR(45) NOT NULL 客户端IP
client_port INT NULL 客户端端口
server_ip VARCHAR(45) NOT NULL 服务器IP
server_port INT NOT NULL 服务器端口
http_method VARCHAR(10) NOT NULL 请求方法
request_path VARCHAR(500) NOT NULL 请求路径
request_url VARCHAR(1000) NOT NULL 完整请求URL
user_agent VARCHAR(1000) NULL User-Agent
device_info TEXT NULL 设备信息JSON
response_status INT NULL HTTP响应状态码
processing_time_ms BIGINT NULL 处理耗时(毫秒)
request_size BIGINT NULL 请求体大小(字节)
response_size BIGINT NULL 响应体大小(字节)
x_forwarded_for VARCHAR(500) NULL X-Forwarded-For
x_real_ip VARCHAR(45) NULL X-Real-IP
referer VARCHAR(1000) NULL Referer
operation_type VARCHAR(50) NULL 操作类型
operation_result VARCHAR(20) NULL 操作结果
error_message TEXT NULL 错误信息
session_id VARCHAR(100) NULL 会话ID
access_time DATETIME NOT NULL 访问时间
created_at DATETIME NOT NULL, DEFAULT CURRENT_TIMESTAMP 创建时间

索引:

  • idx_user_id ON user_id
  • idx_phone_number ON phone_number
  • idx_client_ip ON client_ip
  • idx_access_time ON access_time
  • idx_operation_type ON operation_type
  • idx_operation_result ON operation_result
  • idx_client_ip_access_time ON (client_ip, access_time)
  • idx_user_id_access_time ON (user_id, access_time)

14. app_version - 应用版本管理表

字段 类型 约束 说明
id BIGINT PRIMARY KEY, AUTO_INCREMENT 主键ID
version_name VARCHAR(20) UNIQUE, NOT NULL 版本名称(如v1.06)
version_code INT UNIQUE, NOT NULL 版本号(如106)
min_supported_version VARCHAR(20) NOT NULL 最低支持版本
min_supported_code INT NOT NULL 最低支持版本号
is_force_update BOOLEAN NOT NULL, DEFAULT FALSE 是否强制更新
update_message TEXT 更新提示信息
download_url VARCHAR(500) 下载链接
is_active BOOLEAN NOT NULL, DEFAULT TRUE 是否启用
created_at DATETIME NOT NULL, DEFAULT CURRENT_TIMESTAMP 创建时间
updated_at DATETIME NOT NULL, DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP 更新时间

索引:

  • uk_version_name UNIQUE ON version_name
  • uk_version_code UNIQUE ON version_code
  • idx_is_active ON is_active
  • idx_created_at ON created_at

二、app (Android 客户端本地 Room 数据库)

1. divination_record - 解卦记录表

字段 类型 约束 说明
id BIGINT PRIMARY KEY, AUTO_INCREMENT 主键ID
question_type VARCHAR(50) NOT NULL 问题类型
question TEXT NOT NULL 用户问题
hexagram_data TEXT NOT NULL 卦象数据JSON
ai_result TEXT NOT NULL AI解卦结果
timestamp BIGINT NOT NULL 创建时间戳
is_synced BOOLEAN DEFAULT FALSE 是否已同步到云端
is_deleted BOOLEAN DEFAULT FALSE 是否已删除

三、数据库初始化文件位置

文件 说明
login-service/src/main/resources/db/init.sql 初始化表结构
login-service/src/main/resources/db/migration.sql 迁移脚本
login-service/src/main/resources/db/migration/V1_4__Create_sensitive_word_violations_table.sql 敏感词表创建
login-service/src/main/resources/db/migration/V1_5__Enhance_sensitive_word_violations_table.sql 敏感词表增强

四、Entity 类位置

Entity 类 表名 位置
UsersEntity users login-service/src/main/kotlin/com/eryao/login/entity/UsersEntity.kt
VerificationCode verification_codes login-service/src/main/kotlin/com/eryao/login/entity/VerificationCode.kt
User user_profile login-service/src/main/kotlin/com/eryao/login/entity/User.kt
UserToken user_tokens login-service/src/main/kotlin/com/eryao/login/entity/UserToken.kt
UserFeedback user_feedback login-service/src/main/kotlin/com/eryao/login/entity/UserFeedback.kt
UserCoin user_coin login-service/src/main/kotlin/com/eryao/login/entity/UserCoin.kt
Notification notification login-service/src/main/kotlin/com/eryao/login/entity/Notification.kt
PaymentRecord payment_record login-service/src/main/kotlin/com/eryao/login/entity/PaymentRecord.kt
PaymentOrder payment_order login-service/src/main/kotlin/com/eryao/login/entity/PaymentOrder.kt
SensitiveWordViolation sensitive_word_violations login-service/src/main/kotlin/com/eryao/login/entity/SensitiveWordViolation.kt
DivinationRecord user_divination_records login-service/src/main/kotlin/com/eryao/login/entity/DivinationRecord.kt
DivinationHistory user_divination_history login-service/src/main/kotlin/com/eryao/login/entity/DivinationRecord.kt
NetworkAccessLog network_access_logs login-service/src/main/kotlin/com/eryao/login/entity/NetworkAccessLog.kt
AppVersion app_version login-service/src/main/kotlin/com/eryao/login/entity/AppVersion.kt
DivinationRecord (Room) divination_record app/src/main/java/com/example/eryaoapp/database/DivinationRecord.kt