Skip to content

Database Schema

Matt Ha edited this page Feb 2, 2018 · 9 revisions

Users

Column Data Type Details
id integer not null, primary key
username string not null, unique
email string not null, unique
password_digest string not null
session_token string not null, unique, indexed
img_url string
created_at datetime not null
updated_at datetime not null

Associations

has_many :posts,
has_many :authored_comments
has_many :liked_comments
has_many :liked_posts
has_many :saved_posts
has_many :followed_users
has_many :following_users

Posts

Column Data Type Details
id integer not null, primary key
description string
img_url string not null
author_id string not null, indexed
created_at datetime not null
updated_at datetime not null

Associations

has_many :comments,
has_many :user_likes
has_many :user_saves
belongs_to :user

Comments

Column Data Type Details
id integer not null, primary key
body string not null
author_id string not null, indexed
post_id string not null, indexed
created_at datetime not null
updated_at datetime not null

Associations

has_many :user_likes
belongs_to :post
belongs_to :user

Follows

Column Data Type Details
id integer not null, primary key
follower_id string not null, indexed
followed_id string not null, indexed
created_at datetime not null
updated_at datetime not null

Associations

belongs_to :follower
belongs_to :followed_user

Likes

Column Data Type Details
id integer not null, primary key
post_id string not null, indexed
created_at datetime not null
updated_at datetime not null

Associations

belongs_to :user
belongs_to :post
belongs_to :id

Stories

TODO: Add schema if there is time to implement

Clone this wiki locally