Notifications
Table: public.notifications
Columns
| Column |
Type |
Default |
Description |
id |
bigint |
PK auto-increment |
Notification ID |
user_id |
uuid |
FK → profiles(id) |
Recipient |
type |
text |
'system' |
order_created, order_status, promotion_activated, system, etc. |
title |
text |
NOT NULL |
Notification title |
message |
text |
NOT NULL |
Notification body |
related_id |
text |
nullable |
FK reference |
related_type |
text |
nullable |
Entity type |
is_read |
boolean |
false |
Read status |
read_at |
timestamptz |
nullable |
Read timestamp |
data |
jsonb |
nullable |
Arbitrary payload |
created_at |
timestamptz |
now() |
|
Indexes
idx_notifications_user_id on user_id
idx_notifications_user_unread on (user_id) WHERE is_read = false
Notification Types
| Type |
Trigger |
Recipients |
order_created |
New order placed |
Sellers + Admins |
order_status |
Status changed |
Customer |
product_approved |
Admin approves product |
Seller |
product_rejected |
Admin rejects product |
Seller |
pharmacy_approved |
Admin approves pharmacy |
Applicant |
pharmacy_rejected |
Admin rejects pharmacy |
Applicant |
promotion_activated |
Admin starts promotion |
All customers |
offer_created |
Seller creates offer |
Admins |
system |
General |
Targeted |
RLS
- Owner: full CRUD on own notifications
- Admin: can insert for any user (
createNotificationForAllCustomers)