feat: Phase 8.1 — 定义 MessageRepository 接口和消息表迁移脚本
This commit is contained in:
1
backend/migrations/002_messages.down.sql
Normal file
1
backend/migrations/002_messages.down.sql
Normal file
@@ -0,0 +1 @@
|
||||
DROP TABLE IF EXISTS messages;
|
||||
17
backend/migrations/002_messages.up.sql
Normal file
17
backend/migrations/002_messages.up.sql
Normal file
@@ -0,0 +1,17 @@
|
||||
-- 消息表
|
||||
CREATE TABLE IF NOT EXISTS messages (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
session_id UUID NOT NULL,
|
||||
role VARCHAR(16) NOT NULL, -- "user" | "assistant" | "system"
|
||||
content TEXT NOT NULL,
|
||||
tokens_used INTEGER NOT NULL DEFAULT 0,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
||||
);
|
||||
|
||||
-- 按会话查询消息(分页核心索引)
|
||||
CREATE INDEX IF NOT EXISTS idx_messages_session_id_created_at
|
||||
ON messages(session_id, created_at);
|
||||
|
||||
-- 按会话查询最后一条消息
|
||||
CREATE INDEX IF NOT EXISTS idx_messages_session_id_id_desc
|
||||
ON messages(session_id, id DESC);
|
||||
Reference in New Issue
Block a user