From f163b9c370bd2a17a50f496e0096326a87589229 Mon Sep 17 00:00:00 2001 From: sam Date: Wed, 1 Apr 2026 16:25:26 +0200 Subject: [PATCH] fix: correct chat_histories FK to reference projects(guid) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #2 — project_id on chat_histories was referencing projects(id) (bigserial) instead of projects(guid) (uuid). Added migration 019 to repair existing deployments and corrected 018 for fresh installs. --- migrations/018_chat_histories.sql | 2 +- migrations/019_fix_chat_histories_fk.sql | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 migrations/019_fix_chat_histories_fk.sql diff --git a/migrations/018_chat_histories.sql b/migrations/018_chat_histories.sql index fbe3b28..b9836e7 100644 --- a/migrations/018_chat_histories.sql +++ b/migrations/018_chat_histories.sql @@ -7,7 +7,7 @@ CREATE TABLE IF NOT EXISTS chat_histories ( title TEXT, channel 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 '[]', summary TEXT, metadata JSONB NOT NULL DEFAULT '{}', diff --git a/migrations/019_fix_chat_histories_fk.sql b/migrations/019_fix_chat_histories_fk.sql new file mode 100644 index 0000000..7d88a54 --- /dev/null +++ b/migrations/019_fix_chat_histories_fk.sql @@ -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;