Forum Database Schema database schema
The Forum Database Schema database schema is a DB Planner template with 15 tables, 112 columns and 31 relationships, free to use. Core tables include badges, forums, moderation_actions, post_revisions. It can be opened as an interactive diagram or exported as PostgreSQL, MySQL, or MSSQL DDL.
- Tables
- 15
- Columns
- 112
- Relationships
- 31
- Category
- Social
- Exports
- DBML, SQL, C#
- Price
- Free
What this schema models
A discussion forum database schema designed around the two decisions that determine whether a message board stays fast as it grows. 15 tables and 8 enums covering members and reputation, nested boards, topics and threaded replies with edit history, voting, watch subscriptions with unread tracking, cross-cutting tags, badges, and a full moderation pipeline with reports, actions and scoped bans. THE TWO DECISIONS 1. A TOPIC is not a POST. The topic is the thread container that carries the title, the board, the counters and the sort keys; posts are the replies, with is_first_post marking the opening body so the topic row never has to carry text. Collapsing both into one self-referencing table looks elegant for about a week, and then every board listing query needs a subselect just to find the root row. 2. Denormalised counters are DELIBERATE, not sloppy. A forum index page shows reply count, view count, vote score and last poster for dozens of topics at once. Computing those with aggregates on every page load is the single most common reason a forum falls over under load. They are documented as caches that can always be rebuilt from votes, posts and topic_views. The index that matters most is (forum_id, is_pinned, last_post_at) on topics — that composite IS the board listing query: pinned threads first, then most recent activity. DETAILS WORTH STEALING - forums.last_topic_id is deliberately NOT a foreign key. It is a display cache, and a cascade from it would be a liability during moderation. - votes uses a composite primary key on (user_id, post_id) with a value of +1 or -1, so a vote is idempotent and flipping it is an UPDATE rather than an accumulating pile of rows. - topic_subscriptions stores last_read_post_id as a high-water mark, not a row per post read. Unread count is a range query above that point. - topic_views is pre-aggregated per topic per day rather than one row per hit, and topics.view_count is its running total. - Boards nest hierarchically; tags cut across them. Both exist because a rigid board tree cannot express a cross-cutting subject and a flat tag list cannot express permissions. - A ban is a row in user_bans with a start, an expiry and an optional forum scope — not a boolean on users — so a history of sanctions survives and a per-board ban is possible. - moderation_actions is append-only and logs locking, pinning, moving, merging and deleting, which means moderator activity is itself reviewable. - Posts carry edit history in post_revisions. A forum without that cannot settle an argument about what somebody actually wrote. WHAT YOU GET Clean DBML that imports straight into DB Planner, plus a laid-out board with cards colour-coded by zone — people, structure, content, engagement and moderation — with sticky notes explaining each decision and every table carrying its own Note. Postgres-flavoured types that port cleanly to MySQL or SQL Server. Useful for developers building a community platform or Q&A site, anyone replacing phpBB or Discourse with something custom, and students who need a realistic forum ER diagram for a DBMS project.
Tables (15)
| Table | Columns |
|---|---|
| badges | 6 |
| forums | 11 |
| moderation_actions | 9 |
| post_revisions | 7 |
| posts | 11 |
| reports | 9 |
| tags | 5 |
| topic_subscriptions | 5 |
| topic_tags | 2 |
| topic_views | 5 |
| topics | 15 |
| user_badges | 3 |
| user_bans | 9 |
| users | 11 |
| votes | 4 |
Relationships (31)
forums.parent_id references forums.idmany to onemoderation_actions.moderator_id references users.idmany to onemoderation_actions.report_id references reports.idmany to onemoderation_actions.target_post_id references posts.idmany to onemoderation_actions.target_topic_id references topics.idmany to onemoderation_actions.target_user_id references users.idmany to onepost_revisions.editor_id references users.idmany to onepost_revisions.post_id references posts.idmany to oneposts.author_id references users.idmany to oneposts.reply_to_post_id references posts.idmany to oneposts.topic_id references topics.idmany to onereports.post_id references posts.idmany to onereports.reported_user_id references users.idmany to onereports.reporter_id references users.idmany to onereports.topic_id references topics.idmany to onetopic_subscriptions.last_read_post_id references posts.idmany to onetopic_subscriptions.topic_id references topics.idmany to onetopic_subscriptions.user_id references users.idmany to onetopic_tags.tag_id references tags.idmany to onetopic_tags.topic_id references topics.idmany to onetopic_views.topic_id references topics.idmany to onetopics.author_id references users.idmany to onetopics.forum_id references forums.idmany to onetopics.last_post_user_id references users.idmany to oneuser_badges.badge_id references badges.idmany to oneuser_badges.user_id references users.idmany to oneuser_bans.forum_id references forums.idmany to oneuser_bans.issued_by references users.idmany to oneuser_bans.user_id references users.idmany to onevotes.post_id references posts.idmany to onevotes.user_id references users.idmany to one
How to use this template
- Open the diagram to see the tables and how they relate.
- Copy it into your workspace. You get your own editable copy.
- Export it as PostgreSQL, MySQL, or MSSQL DDL, or as C# models.
Frequently asked questions
- What is in the Forum Database Schema schema?
- 15 tables and 31 relationships, across 112 columns. The table names and the full relationship list are shown on this page.
- Can I export it to PostgreSQL or MySQL?
- Yes. Every DB Planner template exports as DBML, PostgreSQL, MySQL, or MSSQL DDL, and as C# models.
- Is this template free?
- Yes. You can open it in the browser without an account, and copy it into your own workspace with a free DB Planner account.
- Can I change it after copying it?
- Yes. A copy is yours: you can rename tables, add columns, and export it. Changes the author makes later do not affect your copy.