fix(schema): support anonymous users in conversations and user_memories
- Remove foreign key constraint from conversations.user_id - Remove foreign key constraint from user_memories.user_id - Add FACT and INTENT to user_memories.memory_type enum - Both tables now support anonymous users (UUID without registration) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
10a2449d05
commit
925283d8e6
|
|
@ -60,8 +60,9 @@ CREATE INDEX idx_users_created_at ON users(created_at);
|
|||
-- ===========================================
|
||||
CREATE TABLE conversations (
|
||||
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
|
||||
-- 所属用户ID
|
||||
user_id UUID REFERENCES users(id) ON DELETE CASCADE,
|
||||
-- 所属用户ID(可为空,支持匿名用户;如果关联注册用户则有外键)
|
||||
-- 注意:不使用外键约束,允许匿名访客使用(user_id为随机UUID或null)
|
||||
user_id UUID,
|
||||
-- 对话状态: ACTIVE(进行中), ENDED(已结束), ARCHIVED(已归档)
|
||||
status VARCHAR(20) NOT NULL DEFAULT 'ACTIVE'
|
||||
CHECK (status IN ('ACTIVE', 'ENDED', 'ARCHIVED')),
|
||||
|
|
@ -1284,8 +1285,8 @@ CREATE INDEX idx_knowledge_chunks_embedding ON knowledge_chunks USING ivfflat (e
|
|||
-- ===========================================
|
||||
CREATE TABLE user_memories (
|
||||
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
|
||||
-- 用户ID
|
||||
user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
-- 用户ID(支持匿名用户,不使用外键约束)
|
||||
user_id UUID NOT NULL,
|
||||
-- 记忆类型
|
||||
memory_type VARCHAR(30) NOT NULL
|
||||
CHECK (memory_type IN (
|
||||
|
|
@ -1299,7 +1300,9 @@ CREATE TABLE user_memories (
|
|||
'QUESTION_ASKED', -- 问过的问题
|
||||
'CONCERN', -- 关注点
|
||||
'PREFERENCE', -- 偏好设置
|
||||
'CUSTOM' -- 自定义
|
||||
'CUSTOM', -- 自定义
|
||||
'FACT', -- 用户陈述的事实
|
||||
'INTENT' -- 用户意图
|
||||
)),
|
||||
-- 记忆内容
|
||||
content TEXT NOT NULL,
|
||||
|
|
|
|||
Loading…
Reference in New Issue