Chats & Messages¶
chats¶
Table: public.chats
| Column | Type | Default | Description |
|---|---|---|---|
id |
uuid |
PK | UUID |
product_id |
uuid |
FK → products(id) nullable |
|
order_id |
uuid |
FK → orders(id) nullable |
|
customer_id |
uuid |
FK → profiles(id) |
Customer |
pharmacy_id |
uuid |
FK → sellers(id) |
Pharmacy |
is_active |
boolean |
true |
|
last_message |
text |
nullable | Preview |
last_message_time |
timestamptz |
nullable | |
created_at |
timestamptz |
now() |
chat_participants¶
Table: public.chat_participants
| Column | Type | Default | Description |
|---|---|---|---|
id |
uuid |
PK | UUID |
chat_id |
uuid |
FK → chats(id) |
|
user_id |
uuid |
FK → profiles(id) |
|
joined_at |
timestamptz |
now() |
messages¶
Table: public.messages
| Column | Type | Default | Description |
|---|---|---|---|
id |
uuid |
PK | UUID |
chat_id |
uuid |
FK → chats(id) |
Parent chat |
sender_id |
uuid |
FK → profiles(id) |
Sender |
message |
text |
nullable | |
message_type |
text |
'text' |
text, image, system |
attachment_url |
text |
nullable | File |
is_read |
boolean |
false |
|
read_at |
timestamptz |
nullable | |
created_at |
timestamptz |
now() |
Indexes¶
idx_chats_customeronchats(customer_id)idx_chats_pharmacyonchats(pharmacy_id)idx_messages_chatonmessages(chat_id)idx_chat_participants_chatonchat_participants(chat_id)
Related¶
- Mobile: Chat — Messaging UI
- Mobile: Chat Model — Flutter model
- Realtime — Real-time subscription setup