[GH-ISSUE #11467] feat: Chat Database Schema Update for Better Design, Performance, and Scalability #16241

Closed
opened 2026-04-19 22:13:51 -05:00 by GiteaMirror · 0 comments
Owner

Originally created by @harrywang on GitHub (Mar 9, 2025).
Original GitHub issue: https://github.com/open-webui/open-webui/issues/11467

Check Existing Issues

  • I have searched the existing issues and discussions.

Problem Description

The current chat is saved in the Chat table.

Each chat is one row, with chat field saving all chat messages in json - this can be slow and when the number of messages get large, the json is getting very big and slow.

This could be better designed.

Each chat is a conversation, each message can be in a separate table.

For example, see the schema from Vercel's at chatbot: https://github.com/vercel/ai-chatbot/blob/main/lib/db/schema.ts

How Chats are Stored
1. When a user creates a chat, a new row is inserted into the Chat table.
2. The id is automatically generated using defaultRandom(), ensuring each chat gets a unique identifier.
3. The createdAt field captures the time when the chat was created.
4. The userId field links the chat to the user who created it.
5. The visibility field determines if the chat is public or private.

How Messages are Associated with Chats

The Message table links messages to chats:
• The chatId column in the Message table references the id column in the Chat table.
• When a user sends a message in a chat, it is saved with:
• chatId (to associate it with a chat),
• role (e.g., ‘user’, ‘assistant’),
• content (stored as JSON),
• createdAt (timestamp of the message).

I think this is a much better design.

FYI, this is the current Chat table:
Image

Desired Solution you'd like

a new database design for better scalability and performance.

Alternatives Considered

No response

Additional Context

No response

Originally created by @harrywang on GitHub (Mar 9, 2025). Original GitHub issue: https://github.com/open-webui/open-webui/issues/11467 ### Check Existing Issues - [x] I have searched the existing issues and discussions. ### Problem Description The current chat is saved in the Chat table. Each chat is one row, with chat field saving all chat messages in json - this can be slow and when the number of messages get large, the json is getting very big and slow. This could be better designed. Each chat is a conversation, each message can be in a separate table. For example, see the schema from Vercel's at chatbot: https://github.com/vercel/ai-chatbot/blob/main/lib/db/schema.ts How Chats are Stored 1. When a user creates a chat, a new row is inserted into the Chat table. 2. The id is automatically generated using defaultRandom(), ensuring each chat gets a unique identifier. 3. The createdAt field captures the time when the chat was created. 4. The userId field links the chat to the user who created it. 5. The visibility field determines if the chat is public or private. How Messages are Associated with Chats The Message table links messages to chats: • The chatId column in the Message table references the id column in the Chat table. • When a user sends a message in a chat, it is saved with: • chatId (to associate it with a chat), • role (e.g., ‘user’, ‘assistant’), • content (stored as JSON), • createdAt (timestamp of the message). I think this is a much better design. FYI, this is the current Chat table: ![Image](https://github.com/user-attachments/assets/7195affa-ffaf-4ec6-99ba-906d5ff88b4c) ### Desired Solution you'd like a new database design for better scalability and performance. ### Alternatives Considered _No response_ ### Additional Context _No response_
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/open-webui#16241