Skip to content

Database Schema

Tamir Karssli edited this page Feb 28, 2019 · 10 revisions

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
caption text
user_id integer not null, indexed, foreign key
created_at datetime not null
updated_at datetime not null
  • user_id references users id
  • index on user_id

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 id
  • post_id references posts id
  • index on [post_id, user_id], unique: true
  • index on user_id, unique: true

comments

column name data type details
id integer not null, primary key
body text not null
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 id
  • post_id references posts id

Follows

column name data type details
id integer not null, primary key
user_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
  • user_id references users id
  • follower_id references users id
  • index on [follower_id, user_id], unique: true
  • index on user_id, unique: true

Clone this wiki locally