Social Media Database Schema database schema
The Social Media Database Schema database schema by Colton Bristow has 35 tables (users, profiles, sessions, follows and 31 more), 203 columns and 66 relationships, documented column by column.
- Tables
- 35
- Columns
- 203
- Relationships
- 66
- Enums
- 13
Tables (35)
| Table | Columns | Description |
|---|---|---|
| users | 9 | Handle and credentials only. Everything a visitor sees lives in profiles, so a rename never touches the auth row. |
| profiles | 9 | One-to-one with users. Split out because it is read on every profile view and written far more often than credentials. |
| sessions | 9 | One row per signed-in device. revoked_at null means live, which is what powers a log-out-everywhere button. |
| follows | 4 | Directed. Mutual following is two rows. status pending covers follow requests to a private account. |
| blocks | 3 | Blocking is mutual invisibility and should also delete any follows rows in both directions. |
| mutes | 3 | Unlike a block, a mute is invisible to the muted user and leaves the follow intact. It only filters the feed. |
| lists | 6 | |
| list_members | 3 | Membership does not require following, which is what makes lists useful for reading without subscribing. |
| posts | 14 | Self-referencing for threads. The three count columns are denormalised caches, rebuildable from the engagement tables. deleted_at is a soft delete so replies do not orphan. |
| post_media | 10 | Bytes live in object storage. This table holds the pointer and the metadata a client needs to lay out before the file loads. |
| hashtags | 4 | Stored once, lowercased. usage_count is a cache that drives trending. |
| post_hashtags | 2 | |
| post_mentions | 2 | Extracted at write time rather than parsed on read, so the mentions tab is a plain index lookup. |
| post_likes | 3 | The composite primary key is what makes a like idempotent. Never store a like as a counter alone. |
| reposts | 5 | A null comment is a plain repost; a non-null one is a quote. Both fan out to followers. |
| bookmarks | 3 | Private by definition. Never generates a notification. |
| comments | 9 | Separate from posts on purpose: comments are never independently followable and never enter the fan-out feed. |
| comment_likes | 3 | |
| polls | 5 | One poll per post. Results are counted from poll_votes, never stored on the option. |
| poll_options | 4 | |
| poll_votes | 3 | Single-choice polls add a partial unique index on (poll_id, user_id) through the option join. |
| stories | 7 | expires_at is written at creation, not inferred. The index on it is what lets a sweeper reap expired rows cheaply. |
| story_views | 3 | The composite key means a re-watch does not inflate the viewer list. |
| conversations | 6 | last_message_at is denormalised so the inbox sorts without touching messages. |
| conversation_participants | 6 | left_at null means currently in the thread. Keeping the row preserves who saw what before they left. |
| messages | 8 | The composite index on conversation and time is the single most important index in a chat system. |
| message_attachments | 6 | |
| message_reads | 4 | A high-water mark per participant, not a row per message. Unread count is a range query above this point. |
| feed_entries | 7 | The materialised timeline, written on fan-out. reason and source_user_id are what let the UI say why a post is here. |
| notifications | 8 | actor_id null is a system notification. The partial index on unread is what keeps the badge count cheap. |
| notification_preferences | 5 | One row per user per notification type. Absent row means fall back to the product default. |
| groups | 8 | |
| group_members | 4 | Posts carry a nullable group_id, so one posts table serves both the public timeline and every group. |
| reports | 9 | Exactly one of the three target columns is set, enforced by a check constraint. |
| moderation_actions | 9 | Append-only. A suspension is not a flag on users, it is a row here with an expires_at, so the history survives the appeal. |
Enums (13)
- account_status
- active, suspended, deactivated, deleted
- follow_status
- pending, accepted
- post_type
- text, media, poll, repost, reply
- post_visibility
- public, followers, mentioned, group, private
- media_type
- image, video, gif, audio, file
- conversation_type
- direct, group
- feed_reason
- followed, reposted, liked_by_followee, group, recommended
- notification_type
- follow, follow_request, like, comment, reply, mention, repost, message, group_invite, system
- group_privacy
- public, closed, secret
- group_role
- owner, admin, moderator, member
- report_reason
- spam, harassment, hate_speech, violence, nudity, misinformation, impersonation, other
- report_status
- open, reviewing, actioned, dismissed
- moderation_action_type
- warn, remove_content, restrict, suspend, ban, no_action
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.