summaryrefslogtreecommitdiff
path: root/makima/migrations/20250112100000_create_contract_chat_history.sql
diff options
context:
space:
mode:
authorsoryu <soryu@soryu.co>2026-01-11 05:52:14 +0000
committersoryu <soryu@soryu.co>2026-01-15 00:21:16 +0000
commit87044a747b47bd83249d61a45842c7f7b2eae56d (patch)
treeef2000ce79ffcc2723ef841acef5aa1deb1d5378 /makima/migrations/20250112100000_create_contract_chat_history.sql
parent077820c4167c168072d217a1b01df840463a12a8 (diff)
downloadsoryu-87044a747b47bd83249d61a45842c7f7b2eae56d.tar.gz
soryu-87044a747b47bd83249d61a45842c7f7b2eae56d.zip
Contract system
Diffstat (limited to 'makima/migrations/20250112100000_create_contract_chat_history.sql')
-rw-r--r--makima/migrations/20250112100000_create_contract_chat_history.sql33
1 files changed, 33 insertions, 0 deletions
diff --git a/makima/migrations/20250112100000_create_contract_chat_history.sql b/makima/migrations/20250112100000_create_contract_chat_history.sql
new file mode 100644
index 0000000..c4d71d8
--- /dev/null
+++ b/makima/migrations/20250112100000_create_contract_chat_history.sql
@@ -0,0 +1,33 @@
+-- Create contract_chat_conversations table for storing conversation threads per contract
+CREATE TABLE IF NOT EXISTS contract_chat_conversations (
+ id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
+ contract_id UUID NOT NULL REFERENCES contracts(id) ON DELETE CASCADE,
+ owner_id UUID NOT NULL,
+ name VARCHAR(255),
+ is_active BOOLEAN NOT NULL DEFAULT true,
+ created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
+ updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
+);
+
+CREATE INDEX idx_contract_chat_conversations_contract ON contract_chat_conversations(contract_id);
+CREATE INDEX idx_contract_chat_conversations_owner ON contract_chat_conversations(owner_id);
+CREATE INDEX idx_contract_chat_conversations_active ON contract_chat_conversations(contract_id, is_active);
+
+CREATE TRIGGER update_contract_chat_conversations_updated_at
+ BEFORE UPDATE ON contract_chat_conversations
+ FOR EACH ROW
+ EXECUTE FUNCTION update_updated_at_column();
+
+-- Create contract_chat_messages table for individual messages
+CREATE TABLE IF NOT EXISTS contract_chat_messages (
+ id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
+ conversation_id UUID NOT NULL REFERENCES contract_chat_conversations(id) ON DELETE CASCADE,
+ role VARCHAR(16) NOT NULL CHECK (role IN ('user', 'assistant', 'error')),
+ content TEXT NOT NULL,
+ tool_calls JSONB,
+ pending_questions JSONB,
+ created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
+);
+
+CREATE INDEX idx_contract_chat_messages_conversation ON contract_chat_messages(conversation_id);
+CREATE INDEX idx_contract_chat_messages_created ON contract_chat_messages(created_at);