Skip to content
Dan Lay edited this page Oct 10, 2022 · 7 revisions

Postgres 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
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
  • has_many videos
  • has_many comments
  • has_many likes
  • has_many subscribers BONUS

videos

column name data type details
id integer not null, primary key
title string not null
description string
uploader_id integer not null, indexed, foreign key
viewer_id integer not null, indexed, foreign key
created_at datetime not null
updated_at datetime not null
  • uploader_id references users
  • index on uploader_id
  • index on viewer_id
  • has_many comments
  • has_many views
  • belongs_to uploader
  • belongs_to viewer

comments

column name data type details
id integer not null, primary key
body text not null
commenter_id integer not null, indexed, foreign key
video_id integer not null, indexed, foreign key
created_at datetime not null
updated_at datetime not null
  • commenter_id references users
  • video_id references videos
  • index on commenter_id
  • index on video_id
  • belongs_to commenter
  • belongs_to video

video_feelings

column name data type details
id integer not null, primary key
video_id integer not null, indexed, foreign key
feeler_id integer not null, indexed, foreign key
is_like boolean not null
created_at datetime not null
updated_at datetime not null
  • feeler_id references users
  • video_id references videos & index on feeler_id
  • index on video_id
  • belongs_to feeler
  • belongs_to video

comment_feelings

column name data type details
id integer not null, primary key
comment_id integer not null, indexed, foreign key
feeler_id integer not null, indexed, foreign key
is_like boolean not null
created_at datetime not null
updated_at datetime not null
  • feeler_id references users
  • comment_id references comments & index on feeler_id
  • index on commenter_id
  • belongs_to feeler
  • belongs to comment

questions:

  • what to do about subscribers and streams?
  • any missing / incorrect associations or indexes?
Clone this wiki locally