Skip to content

Database Schema

ChrisCavs edited this page Jul 5, 2018 · 3 revisions

Database Schema

users

column name data type details
id integer not null, primary key
name string not null, indexed
email string not null, indexed, unique
img_url 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

stories

column name data type details
id integer not null, primary key
title string not null
subtitle string not null
body string not null
image_url string 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

comments

column name data type details
id integer not null, primary key
author_id integer not null, indexed, foreign key
story_id integer not null, indexed, foreign key
body string not null
created_at datetime not null
updated_at datetime not null
  • author_id references users
  • story_id references stories
  • index on author_id
  • index on story_id

followings

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

claps

column name data type details
id integer not null, primary key
user_id integer not null, indexed, foreign key
clapable_id integer not null, indexed, foreign key
clapable_type string not null
created_at datetime not null
updated_at datetime not null
  • user_id references users
  • clapable_id references stories or comments (polymorphic)
  • index on [:clapable_id, :user_id], unique: true
  • index on :user_id, unique: true
Clone this wiki locally