mirror of
https://github.com/patdelphi/suanming.git
synced 2026-03-10 10:33:11 +08:00
feat: refactor AI interpretation system and fix recordId issues
- Refactored AI interpretation table to use proper 1-to-1 relationship with reading records - Fixed recordId parameter passing in AnalysisResultDisplay component - Updated database schema to use reading_id instead of analysis_id - Removed complex string ID generation logic - Fixed TypeScript type definitions for all ID fields - Added database migration scripts for AI interpretation refactoring - Improved error handling and debugging capabilities
This commit is contained in:
@@ -81,8 +81,7 @@ CREATE INDEX IF NOT EXISTS idx_sessions_expires ON user_sessions(expires_at);
|
||||
CREATE TABLE IF NOT EXISTS ai_interpretations (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
user_id INTEGER NOT NULL,
|
||||
analysis_id INTEGER NOT NULL, -- 关联到numerology_readings表的id
|
||||
analysis_type TEXT NOT NULL CHECK (analysis_type IN ('bazi', 'ziwei', 'yijing')),
|
||||
reading_id INTEGER NOT NULL, -- 直接关联到numerology_readings表的id
|
||||
content TEXT NOT NULL, -- AI解读的完整内容
|
||||
model TEXT, -- 使用的AI模型
|
||||
tokens_used INTEGER, -- 消耗的token数量
|
||||
@@ -91,12 +90,13 @@ CREATE TABLE IF NOT EXISTS ai_interpretations (
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE,
|
||||
FOREIGN KEY (analysis_id) REFERENCES numerology_readings(id) ON DELETE CASCADE
|
||||
FOREIGN KEY (reading_id) REFERENCES numerology_readings(id) ON DELETE CASCADE,
|
||||
UNIQUE(reading_id) -- 确保1对1关系
|
||||
);
|
||||
|
||||
-- 创建AI解读相关索引
|
||||
CREATE INDEX IF NOT EXISTS idx_ai_interpretations_user_id ON ai_interpretations(user_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_ai_interpretations_analysis_id ON ai_interpretations(analysis_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_ai_interpretations_reading_id ON ai_interpretations(reading_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_ai_interpretations_created_at ON ai_interpretations(created_at DESC);
|
||||
|
||||
-- 触发器:自动更新updated_at字段
|
||||
|
||||
Reference in New Issue
Block a user