Skip to content
Sam edited this page Mar 1, 2019 · 7 revisions

Database Schema

users

Column Name Data Type Details
id integer not null, primary key
name string not null
username string not null
email string not null, indexed, unique
profile_body string not null
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 session_token, unique: true
  • index on email, unique: true

posts

Column Name Data Type Details
id integer not null, indexed, primary key
body string allow null
author_id integer not null, foreign key
created_at datetime not null
updated_at datetime not null
  • index on author_id
  • author_id references users

post_likes

Column Name Data Type Details
id integer not null, primary key
user_id integer not null. foreign key, indexed
image_id integer not null, foreign key, indexed
created_at datetime not null
updated_at datetime not null
  • index on user_id, unique: true
  • index on [user_id, image_id], unique: true
  • index on image_id
  • user_id references users
  • image_id references images

comments

Column Name Data Type Details
id integer not null, primary key
body string not null
user_id integer Allow null, foreign key, indexed
parent_id integer Allow null, foreign key, indexed
created_at datetime not null
updated_at datetime not null
  • index on parent_id
  • index on user_id
  • parent_id references comments
  • user_id references user_id

follows

Column Name Data Type Details
id integer not null, primary key
followed_id integer Allow null, foreign key, indexed
follower_id integer not null, foreign key, indexed
created_at datetime not null
updated_at datetime not null
  • index on [followed_id, follower_id] unique: true;
  • followed_id references users
  • follower_id references users
Clone this wiki locally