posts table

The posts table in the Reddit Clone Database Schema schema has 41 columns, keyed by id, with 8 foreign keys to polls, subreddits, users, flairs and 3 more. 10 columns in post_media, comments, scheduled_posts, collection_posts and 6 more reference it.

The five score columns are the whole ranking design: each Reddit sort is a DIFFERENT function of the same votes, so each gets its own indexed column written when a vote lands. (subreddit_id, is_stickied, hot_score) IS the front page query. removed_at is a moderator and deleted_at is the author, which is exactly the difference between [removed] and [deleted] - collapsing them is the most common mistake in a Reddit clone. is_contest_mode randomises comment order and hides scores, which is why it belongs on the post rather than in a setting. author_id is nullable so a deleted account leaves the post standing.

Columns (41)

Columns of the posts table
ColumnTypeConstraintsDescription
iduuidprimary key, references polls.post_id
subreddit_iduuidnot null, references subreddits.id
author_iduuidreferences users.id
kindpost_kindnot null
titlevarchar(300)not null
slugvarchar(120)not null
urlvarchar(2000)
domainvarchar(255)
body_mdtext
thumbnail_urlvarchar(500)
flair_iduuidreferences flairs.id
flair_text_overridevarchar(64)
crosspost_parent_iduuidreferences posts.id
collection_iduuidreferences collections.id
is_nsfwbooleannot null
is_spoilerbooleannot null
is_original_contentbooleannot null
is_lockedbooleannot null
is_stickiedbooleannot null
is_archivedbooleannot null
is_contest_modebooleannot null
distinguished_asdistinguish_kind
is_promotedbooleannot null
upvotesintegernot null
downvotesintegernot null
scoreintegernot null
display_seedintegernot null
upvote_ratiodoublenot null
comment_countintegernot null
award_countintegernot null
hot_scoredoublenot null
best_scoredoublenot null
top_scoreintegernot null
controversial_scoredoublenot null
rising_scoredoublenot null
created_attimestamptznot null
edited_attimestamptz
removed_attimestamptz
removed_byuuidreferences users.id
removal_reason_iduuidreferences removal_reasons.id
deleted_attimestamptz

Indexes (10)

  • (subreddit_id, is_stickied, hot_score)
  • (subreddit_id, top_score)
  • (subreddit_id, created_at)
  • (subreddit_id, rising_score)
  • (subreddit_id, slug) unique
  • (author_id, created_at)
  • (crosspost_parent_id)
  • (collection_id)
  • (domain)
  • (is_promoted, created_at)

Relationships