Forum Database Schema database schema
The Forum Database Schema database schema by Colton Bristow has 15 tables (users, badges, user_badges, forums and 11 more), 112 columns and 31 relationships, documented column by column.
- Tables
- 15
- Columns
- 112
- Relationships
- 31
- Enums
- 8
Tables (15)
| Table | Columns | Description |
|---|---|---|
| users | 11 | reputation and post_count are caches rebuildable from votes and posts. The reputation index is what makes a leaderboard cheap. |
| badges | 6 | The catalog of awardable badges. Criteria live in application code; this table only names the award. |
| user_badges | 3 | Composite key means a badge cannot be awarded twice. Repeatable awards would need a sequence column instead. |
| forums | 11 | Self-referencing so a board can hold sub-boards. last_topic_id is deliberately not a foreign key: it is a display cache, and a cascade from it would be a liability. |
| tags | 5 | Cross-cutting labels that work across boards, which is what a rigid board hierarchy cannot express. |
| topic_tags | 2 | |
| topics | 15 | The thread container. The composite index on forum, pinned and last_post_at IS the board listing query — pinned first, then most recent activity. |
| posts | 11 | is_first_post marks the opening body of the thread, so the topic row never has to carry text. deleted_at is a soft delete so replies below it do not orphan. |
| post_revisions | 7 | Edit history, append-only. A forum without this cannot settle an argument about what somebody actually wrote. |
| votes | 4 | value is +1 or -1, constrained by a check. The composite key makes a vote idempotent and lets a user flip it with an UPDATE rather than accumulating rows. |
| topic_subscriptions | 5 | last_read_post_id is a high-water mark, not a row per post read. Unread count is a range query above it. |
| topic_views | 5 | Pre-aggregated per topic per day, not one row per hit. topics.view_count is the running total of this table. |
| reports | 9 | Exactly one of the three target columns is set, enforced by a check constraint. The status index is the moderation queue. |
| moderation_actions | 9 | Append-only. Locking, pinning, merging and deleting all land here, so moderator activity is itself reviewable. |
| user_bans | 9 | A ban is a row with an expiry, not a flag on users, so a history of sanctions survives. expires_at null is permanent; forum_id set scopes it to one board. |
Enums (8)
- user_status
- active, suspended, banned, deactivated
- badge_tier
- bronze, silver, gold
- topic_status
- open, locked, archived, deleted, moved
- subscription_level
- watching, tracking, muted
- report_reason
- spam, abuse, off_topic, duplicate, illegal, other
- report_status
- open, reviewing, actioned, dismissed
- moderation_action_type
- lock_topic, unlock_topic, pin_topic, move_topic, merge_topic, delete_post, restore_post, warn_user, ban_user
- ban_scope
- site, forum, posting_only
Document your own schema
This page is published from DB Planner, a collaborative ER diagram tool. Write the schema in the DBML editor or import it from SQL, then publish docs like these from the project's sharing settings.