messages table
The messages table in the Reddit Clone Database Schema schema has 9 columns, keyed by id, with 3 foreign keys to users and messages.
Private messages between two people, threaded by parent_id. Kept apart from modmail because a message to a person and a message to a moderator team are different objects with different read semantics.
Columns (9)
| Column | Type | Constraints | Description |
|---|---|---|---|
| id | uuid | primary key | |
| sender_id | uuid | references users.id | |
| recipient_id | uuid | not null, references users.id | |
| parent_id | uuid | references messages.id | |
| subject | varchar(200) | not null | |
| body_md | text | not null | |
| created_at | timestamptz | not null | |
| read_at | timestamptz | ||
| deleted_at | timestamptz |
Indexes (3)
(recipient_id, created_at)(recipient_id, read_at)(parent_id)
Relationships
messages.sender_idreferencesusers.idmessages.recipient_idreferencesusers.idmessages.parent_idreferencesmessages.id