schema - rlachivirus/WEbook GitHub Wiki

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

// Index on foreign keys and columns that will be frequently searched by

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
  • index on author_id
  • author_id references users

Comments

Column Name Data Type Details
id integer not null, primary key
body text not null
author_id integer not null, indexed, foreign key
post_id integer not null, indexed, foreign key
parent_comment_id integer optional, indexed, foreign key
created_at datetime not null
updated_at datetime not null
  • index on author_id
  • index on parent_comment_id
  • author_id references Users
  • parent_comment_id references Posts

Friends

Column Name Data Type Details
id integer not null, primary key
user_id integer not null
friend_id integer not null, indexed, foreign key
created_at datetime not null
updated_at datetime not null
  • index on user_id
  • user_id references Users
  • index on friend_id
  • friend_id references Users

BONUS

Likes

Column Name Data Type Details
id integer not null, primary key
like_id integer not null, indexed
like_type string not null, indexed
created_at datetime not null
updated_at datetime not null
  • index on like_id
  • like_id references Users, Posts, and Comments