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.

ER diagram of the Forum Database Schema schema, showing 15 tables and their relationships
FIG. 1: entity relationship diagram, 15 tables
Tables
15
Columns
112
Relationships
31
Enums
8

Tables (15)

Tables in the Forum Database Schema schema
TableColumnsDescription
users11reputation and post_count are caches rebuildable from votes and posts. The reputation index is what makes a leaderboard cheap.
badges6The catalog of awardable badges. Criteria live in application code; this table only names the award.
user_badges3Composite key means a badge cannot be awarded twice. Repeatable awards would need a sequence column instead.
forums11Self-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.
tags5Cross-cutting labels that work across boards, which is what a rigid board hierarchy cannot express.
topic_tags2
topics15The thread container. The composite index on forum, pinned and last_post_at IS the board listing query — pinned first, then most recent activity.
posts11is_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_revisions7Edit history, append-only. A forum without this cannot settle an argument about what somebody actually wrote.
votes4value 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_subscriptions5last_read_post_id is a high-water mark, not a row per post read. Unread count is a range query above it.
topic_views5Pre-aggregated per topic per day, not one row per hit. topics.view_count is the running total of this table.
reports9Exactly one of the three target columns is set, enforced by a check constraint. The status index is the moderation queue.
moderation_actions9Append-only. Locking, pinning, merging and deleting all land here, so moderator activity is itself reviewable.
user_bans9A 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.

More published database schemas