topics table
The topics table in the Forum Database Schema schema has 15 columns, keyed by id, with 3 foreign keys to forums and users. 6 columns in topic_tags, posts, topic_subscriptions, topic_views and 2 more reference it.
The thread container. The composite index on forum, pinned and last_post_at IS the board listing query — pinned first, then most recent activity.
Columns (15)
| Column | Type | Constraints | Description |
|---|---|---|---|
| id | uuid | primary key | |
| forum_id | uuid | not null, references forums.id | |
| author_id | uuid | not null, references users.id | |
| slug | varchar(200) | not null | |
| title | varchar(255) | not null | |
| status | topic_status | not null | |
| is_pinned | boolean | not null | |
| is_answered | boolean | not null | |
| accepted_post_id | uuid | ||
| reply_count | integer | not null | |
| view_count | integer | not null | |
| vote_score | integer | not null | |
| last_post_at | timestamptz | ||
| last_post_user_id | uuid | references users.id | |
| created_at | timestamptz | not null |
Indexes (4)
(forum_id, is_pinned, last_post_at)(forum_id, slug)unique(author_id, created_at)(status, vote_score)
Relationships
topics.forum_idreferencesforums.idtopics.author_idreferencesusers.idtopics.last_post_user_idreferencesusers.idtopic_tags.topic_idreferencestopicsposts.topic_idreferencestopicstopic_subscriptions.topic_idreferencestopicstopic_views.topic_idreferencestopicsreports.topic_idreferencestopicsmoderation_actions.target_topic_idreferencestopics