Skip to content
DanielGuardado edited this page Jul 24, 2020 · 5 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
birthday date 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 email, unique: true
  • Index on sesion_token, unique: true

videos

Column Name Data Type Details
id integer not null, primary key
description string optional
uploader_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

comments

Column Name Data Type Details
id integer not null, primary key
body string not null
author_id integer not null, indexed, foreign key
parent_comment_id integer indexed, foreign key
video_id integer not null, indexed, foreign key
created_at datetime not null
updated_at datetime not null
  • author_id references users
  • video_id references videos
  • parent_comment_id references comments
  • indexed on [:author_id, :video_id, :parent_comment_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
likeable_type string not null, indexed
created_at datetime not null
updated_at datetime not null
  • user_id references users
  • index on [:likeable_id, :likeable_type, :user_id] unique: true
  • likeable_id references comments
  • likeable_id references likes

followers

Column Name Data Type Details
id integer not null, primary key
follower_id integer not null, indexed, foreign key
followee_id integer not null, indexed, foreign key
created_at datetime not null
updated_at datetime not null
  • follower_id references users
  • followee_id references users
  • index on [:follower_id, :followee_id] unique: true

views

Column Name Data Type Details
id integer not null, primary key
viewer_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
  • viewer_id references users
  • video_id references videos

Clone this wiki locally