Skip to content
AlbertgitC edited this page Oct 10, 2019 · 7 revisions

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
website string
bio text
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

feeds

column name data type details
id integer not null, primary key
body text
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
  • attached :photo

comments

column name data type details
id integer not null, primary key
body text not null
feed_id integer not null, indexed, foreign key
author_id integer not null, foreign key
created_at datetime not null
updated_at datetime not null
  • feed_id references feeds
  • author_id references users

likes

column name data type details
id integer not null, primary key
likeable_id integer not null, indexed, foreign key
likeable_type string not null, indexed
author_id integer not null, foreign key
created_at datetime not null
updated_at datetime not null
  • polymorphic table, likeable_type = feed or comment
  • likeable_id references feeds or comments
  • author_id references users
  • index on [:likeable_id, :likeable_type, :author_id], unique: true

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
  • follower_id references users

Clone this wiki locally