Skip to content
maggiecs edited this page Jan 24, 2019 · 5 revisions

Database Schema

users

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

comments

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

likes

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

follows

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

posts

column name data type details
id integer not null, primary key
author_id integer not null, indexed, foreign key
body text
created_at datetime not null
updated_at datetime not null
  • author_id references author
  • index on :author_id

Clone this wiki locally