fix: correct chat_histories FK to reference projects(guid) #3

Merged
warkanum merged 2 commits from fix/chat-history-fk into main 2026-04-01 14:29:10 +00:00
2 changed files with 12 additions and 1 deletions
Showing only changes of commit f163b9c370 - Show all commits

View File

@@ -7,7 +7,7 @@ CREATE TABLE IF NOT EXISTS chat_histories (
title TEXT, title TEXT,
channel TEXT, channel TEXT,
agent_id TEXT, agent_id TEXT,
project_id UUID REFERENCES projects(id) ON DELETE SET NULL, project_id UUID REFERENCES projects(guid) ON DELETE SET NULL,
messages JSONB NOT NULL DEFAULT '[]', messages JSONB NOT NULL DEFAULT '[]',
summary TEXT, summary TEXT,
metadata JSONB NOT NULL DEFAULT '{}', metadata JSONB NOT NULL DEFAULT '{}',

View File

@@ -0,0 +1,11 @@
-- Migration: 019_fix_chat_histories_fk
-- Fix the project_id foreign key on chat_histories to reference projects(guid)
-- instead of projects(id). This corrects the initial migration (018) which
-- used the wrong column — projects.id is a bigserial, projects.guid is the UUID.
ALTER TABLE chat_histories
DROP CONSTRAINT IF EXISTS chat_histories_project_id_fkey;
ALTER TABLE chat_histories
ADD CONSTRAINT chat_histories_project_id_fkey
FOREIGN KEY (project_id) REFERENCES projects(guid) ON DELETE SET NULL;