messages table

The messages table in the Social Media Database Schema schema has 8 columns, keyed by id, with 3 foreign keys to conversations, users and messages. 2 columns in message_attachments and message_reads reference it.

The composite index on conversation and time is the single most important index in a chat system.

Columns (8)

Columns of the messages table
ColumnTypeConstraintsDescription
iduuidprimary key
conversation_iduuidnot null, references conversations.id
sender_iduuidnot null, references users.id
reply_to_iduuidreferences messages.id
bodyvarchar(4000)
created_attimestamptznot null
edited_attimestamptz
deleted_attimestamptz

Indexes (1)

  • (conversation_id, created_at)

Relationships