users table

The users table in the Reddit Clone Database Schema schema has 20 columns, keyed by id, with 1 foreign key to coin_balances. 95 columns in user_sessions, user_devices, user_blocks, user_follows and 67 more reference it.

The auth row. The four karma columns are rebuildable caches over karma_events, split the way Reddit splits them because post, comment, given-award and received-award karma are earned under different rules. email is nullable because a throwaway account is a first-class citizen. deleted_at keeps the row so old posts still resolve an author id even after the person leaves.

Columns (20)

Columns of the users table
ColumnTypeConstraintsDescription
iduuidprimary key, references coin_balances.user_id
usernamevarchar(20)unique, not null
emailvarchar(255)unique
password_hashvarchar(255)
statusaccount_statusnot null
post_karmaintegernot null
comment_karmaintegernot null
awardee_karmaintegernot null
awarder_karmaintegernot null
total_karmaintegernot null
coin_balanceintegernot null
is_over_18booleannot null
is_employeebooleannot null
has_premiumbooleannot null
premium_untiltimestamptz
accepts_followersbooleannot null
email_verified_attimestamptz
created_attimestamptznot null
last_seen_attimestamptz
deleted_attimestamptz

Indexes (4)

  • (status, created_at)
  • (total_karma)
  • (last_seen_at)
  • (has_premium, premium_until)

Relationships