fix(db): add missing chat_messages.workflow column (user prompts dropped on reload)

✅ merged · #212 · open-legal-products/mike ← jmooves/mike · opened 2mo ago by jmooves · merged 2mo ago by willchen96 · +13 across 2 files · ↗ on GitHub

From the PR description

Problem

User reloading a thread shows the assistant reply but not the user's own prompt - the prompt only ever existed in the browser's in-memory state during the live turn.

User messages are inserted with a workflow field:

  • backend/src/routes/chat.ts - the role: "user" insert
  • backend/src/routes/projectChat.ts - same

and it is read back when rendering chat history (ChatViewUserMessage) to show which workflow a message was sent under.

But chat_messages.workflow is never created - it is absent from backend/schema.sql and no migration adds it. On a fresh self-hosted install, every user-message insert fails with:

PostgREST PGRST204: Could not find the 'workflow' column of 'chat_messages' in the schema cache

The insert result isn't checked, so the failure is silent. The assistant-message insert has no workflow column, so it succeeds. Net effect: reloading a thread shows the assistant reply but not the user's own prompt - the prompt only ever existed in the browser's in-memory state during the live turn.

Reproduction

On a DB built from schema.sql:

insert into chat_messages (chat_id, role, content, files, workflow)
values ('<existing-chat-id>', 'user', '"hi"'::jsonb, null, null);
-- ERROR: PGRST204 - column "workflow" does not exist

The same insert without workflow succeeds. Querying chat_messages afterwards shows only assistant rows.

Fix

Add the workflow jsonb column, mirroring the adjacent content/files jsonb columns:

  • schema.sql - for fresh installs
  • migrations/20260716_01_chat_messages_workflow.sql - idempotent add column if not exists, for existing installs

After applying, user-message inserts succeed and prompts persist across reloads.

My Setup

Mike and all components were installed on a single VM using: Docker 29.6, Node 20, nginx, MinIO (S3 storage) and Supabase.

🤖 Generated with Claude Code. Reviewed by a human, me. :)

Our analysis

Persist chat workflow metadata — read the full analysis →

Think the analysis missed something the PR description covers?

Commits in this PR (1)

SHA Subject Author Date
cfdcda6d fix(db): add missing chat_messages.workflow column JJ 2026-07-16 ↗ GitHub
commit body
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.

Capture this PR into my fork

Download a Markdown prompt that tells Claude how to port every commit in this PR into your working tree. Run it via claude -p < capture-pull-212.md from inside the repo you want the changes in.

⬇ Download capture-pull-212.md