Skip to content
JamesKoenig edited this page Feb 3, 2021 · 4 revisions

Postgres Database Schema

users

column name data type details
id integer not null, primary key
username string not null, indexed, unique
email string not null, indexed, unique
password_digest string not null
session_token string not null, indexed, unique
created_at datetime not null
updated_at datetime not null
  • index on username, unique: true
  • index on email, unique: true
  • index on session_token, unique: true

posts

column name data type details
id integer not null, primary key
body text not null
author_id integer not null, indexed, foreign key
created_at datetime not null
updated_at datetime not null

follows

column name data type details
id integer not null, primary key
followed_id integer not null, indexed, foreign key
follower_id integer not null, indexed, foreign key
created_at datetime not null
updated_at datetime not null
  • followed_id references users
  • follower_id references users
  • index on [:followed_id, :follower_id], unique: true

likes

column name data type details
id integer not null, primary key
user_id integer not null, indexed, foreign key
post_id integer not null, indexed, foreign key
created_at datetime not null
updated_at datetime not null
  • user_id references users
  • post_id references posts
  • index on [:post_id, :user_id], unique: true

(Bonus) Reblogs

column name data type details
id integer not null, primary key
post_id integer not null, indexed, foreign key
reblogger_id integer not null, indexed, foreign key
created_at datetime not null
updated_at datetime not null
  • reblogger_id references users
  • post_id references posts
  • index on [:post_id, :reblogger_id]

Clone this wiki locally