chat_channel_members table
The chat_channel_members table in the Reddit Clone Database Schema schema has 6 columns, with 3 foreign keys to chat_channels, users and chat_messages.
last_read_message_id is a high-water mark, not a row per message read. Unread count is a cheap range query above it, which is the only way a chat badge stays fast.
Columns (6)
| Column | Type | Constraints | Description |
|---|---|---|---|
| channel_id | uuid | not null, references chat_channels.id | |
| user_id | uuid | not null, references users.id | |
| role | chat_member_role | not null | |
| last_read_message_id | uuid | references chat_messages.id | |
| is_muted | boolean | not null | |
| joined_at | timestamptz | not null |
Indexes (1)
(user_id, joined_at)
Relationships
chat_channel_members.channel_idreferenceschat_channels.idchat_channel_members.user_idreferencesusers.idchat_channel_members.last_read_message_idreferenceschat_messages.id