Schema - lisza/storie GitHub Wiki

Database schema

Do I want an email for users?

users

column name data type details
id integer not null, primary key
username string not null, indexed, unique
email string not null, indexed, unique
biography text
image_url string
password_digest string not null
session_token string not null, indexed, unique
created_at datetime not null
updated_at datetime not null
  • indexed on [:username, :email, :session_token]
  • has_many :authored_stories
  • has_many :authored_comments
  • has_many :liked_stories (probs not necessary if we get the num_likes within the story detail, or maybe even store in my state: liked_by_current_user: true/false, to toggle likes more easily?)
  • has_many :followers through: follows source: followers
  • has_many :following through: follows source: following

stories

column name data type details
id integer not null, primary key
title string not null
body text not null
author_id integer not null, indexed, foreign key
created_at datetime not null
updated_at datetime not null
  • author_id references users
  • index on [:author_id]
  • has_many :comments
  • has_many :likes
  • belongs_to :author

comments

column name data type details
id integer not null, primary key
body text not null
story_id integer not null, indexed, foreign key
author_id integer not null, indexed, foreign key
created_at datetime not null
updated_at datetime not null
  • story_id references stories
  • author_id references users
  • index on [:story_id, :author_id]
  • belongs_to :story
  • belongs_to :author

likes

column name data type details
id integer not null, primary key
story_id integer not null, indexed, foreign key
user_id integer not null, indexed, foreign key
created_at datetime not null
updated_at datetime not null
  • story_id references stories
  • user_id references users
  • indexed on [:story_id, :user_id]
  • belongs_to :story
  • belongs_to :author

follows

column name data type details
id integer not null, primary key
follower_id integer not null, indexed, foreign key
following_id integer not null, indexed, foreign key
created_at datetime not null
updated_at datetime not null
  • follower_id and following_id reference users
  • indexed on [:follower_id, :following_id]