2025-01-29 02:21:51 +08:00
|
|
|
-- Your SQL goes here
|
2025-01-29 03:03:11 +08:00
|
|
|
-- Rename existing messages table to messages_deprecated
|
2025-03-01 00:41:44 +08:00
|
|
|
ALTER TABLE messages DROP CONSTRAINT messages_thread_id_fkey;
|
|
|
|
|
2025-01-29 03:03:11 +08:00
|
|
|
ALTER TABLE messages RENAME TO messages_deprecated;
|
|
|
|
|
|
|
|
-- Create new messages table with updated schema
|
|
|
|
CREATE TABLE messages (
|
|
|
|
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
2025-03-05 01:47:16 +08:00
|
|
|
request_message TEXT NOT NULL,
|
|
|
|
response_messages JSONB NOT NULL,
|
|
|
|
reasoning JSONB NOT NULL,
|
2025-03-05 02:51:05 +08:00
|
|
|
title TEXT NOT NULL,
|
2025-03-05 04:09:54 +08:00
|
|
|
raw_llm_messages JSONB NOT NULL,
|
2025-03-05 01:47:16 +08:00
|
|
|
final_reasoning_message TEXT NOT NULL,
|
2025-03-01 00:41:44 +08:00
|
|
|
chat_id UUID NOT NULL REFERENCES chats(id),
|
2025-01-29 03:03:11 +08:00
|
|
|
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
|
|
|
|
updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
|
|
|
|
deleted_at TIMESTAMP WITH TIME ZONE,
|
|
|
|
created_by UUID NOT NULL REFERENCES users(id)
|
|
|
|
);
|
|
|
|
|
2025-02-14 23:32:06 +08:00
|
|
|
|
2025-01-29 03:03:11 +08:00
|
|
|
-- Create indexes for common query patterns
|
2025-04-22 00:58:32 +08:00
|
|
|
CREATE INDEX IF NOT EXISTS messages_chat_id_idx ON messages(chat_id);
|
|
|
|
CREATE INDEX IF NOT EXISTS messages_created_by_idx ON messages(created_by);
|
|
|
|
CREATE INDEX IF NOT EXISTS messages_created_at_idx ON messages(created_at);
|
2025-01-29 03:03:11 +08:00
|
|
|
|
|
|
|
|