buster/api/migrations/2025-01-28-174921_adjust_me.../up.sql

28 lines
964 B
MySQL
Raw Normal View History

-- Your SQL goes here
-- Rename existing messages table to messages_deprecated
2025-03-01 00:41:44 +08:00
ALTER TABLE messages DROP CONSTRAINT messages_thread_id_fkey;
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(),
request_message TEXT NOT NULL,
response_messages JSONB NOT NULL,
reasoning JSONB NOT NULL,
final_reasoning_message TEXT NOT NULL,
2025-03-01 00:41:44 +08:00
chat_id UUID NOT NULL REFERENCES chats(id),
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
-- Create indexes for common query patterns
2025-03-01 00:41:44 +08:00
CREATE INDEX messages_chat_id_idx ON messages(chat_id);
CREATE INDEX messages_created_by_idx ON messages(created_by);
CREATE INDEX messages_created_at_idx ON messages(created_at);