Skip to content

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_customer on chats(customer_id)
  • idx_chats_pharmacy on chats(pharmacy_id)
  • idx_messages_chat on messages(chat_id)
  • idx_chat_participants_chat on chat_participants(chat_id)