From cfdcda6d2c2267ac57834ccab75272b696ca14e0 Mon Sep 17 00:00:00 2001 From: JJ Date: Thu, 16 Jul 2026 07:27:54 +1000 Subject: [PATCH] fix(db): add missing chat_messages.workflow column MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit User messages are persisted with a `workflow` field (backend/src/routes/chat.ts, projectChat.ts) and it is read back when rendering chat history (ChatView -> UserMessage) to show which workflow a message was sent under. But the column is never created by schema.sql or any migration, so every user-message insert fails with PostgREST PGRST204 ("Could not find the 'workflow' column of 'chat_messages'") and is dropped silently (the insert result is not checked). The assistant insert has no workflow column, so it succeeds — the net effect on a self-hosted install is that reloading a thread shows the assistant reply but not the user's prompt. Add the `workflow jsonb` column to schema.sql (fresh installs) and a migration (existing installs), mirroring the adjacent content/files jsonb columns. --- .../20260716_01_chat_messages_workflow.sql | 12 ++++++++++++ backend/schema.sql | 1 + 2 files changed, 13 insertions(+) create mode 100644 backend/migrations/20260716_01_chat_messages_workflow.sql diff --git a/backend/migrations/20260716_01_chat_messages_workflow.sql b/backend/migrations/20260716_01_chat_messages_workflow.sql new file mode 100644 index 0000000..618aa09 --- /dev/null +++ b/backend/migrations/20260716_01_chat_messages_workflow.sql @@ -0,0 +1,12 @@ +-- Add chat_messages.workflow. +-- +-- The app persists a `workflow` field on user messages +-- (backend/src/routes/chat.ts, projectChat.ts) and reads it back when rendering +-- chat history (frontend ChatView -> UserMessage, to show which workflow the +-- message was sent under). The column was referenced in code but never created +-- by schema.sql or any migration, so every user-message insert failed with +-- PostgREST PGRST204 ("Could not find the 'workflow' column") and was dropped +-- silently — user prompts vanished on reload while the assistant reply +-- persisted. Mirrors the existing content/files jsonb columns. +alter table public.chat_messages + add column if not exists workflow jsonb; diff --git a/backend/schema.sql b/backend/schema.sql index 5e48fa5..e2515d2 100644 --- a/backend/schema.sql +++ b/backend/schema.sql @@ -524,6 +524,7 @@ create table if not exists public.chat_messages ( role text not null, content jsonb, files jsonb, + workflow jsonb, citations jsonb, created_at timestamptz not null default now() );