Skip to content

Database Schema

Deborah Wei edited this page Aug 5, 2022 · 5 revisions

Postgres Database Schema

users

column data type details
id integer not null, primary key
username string not null, indexed, unique
name string 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 session_token, unique: true
  • has_many pins
  • has_many boards
  • has_many followers
  • has_many followings

boards

column data type details
id integer not null, primary key
name string not null
user_id integer not null, indexed, foreign_key
created_at datetime not null
updated_at datetime not null
  • index on user_id
  • has_many pins
  • belongs_to user

pins

column data type details
id integer not null, primary key
title string not null
user_id integer not null, indexed, foreign_key
description body
created_at datetime not null
updated_at datetime not null
  • index on user_id
  • belongs_to user

comments

column data type details
id integer not null, primary key
user_id integer not null, indexed, foreign_key
pin_id integer not null, indexed, foreign_key
text body not null
created_at datetime not null
updated_at datetime not null
  • index on user_id
  • index on pin_id
  • belongs_to user
  • belongs_to pin

follows(bonus)

column data type details
id integer not null, primary key
follower_id integer not null, indexed, foreign_key
following_id integer not null, indexed, foreign_key
created_at datetime not null
updated_at datetime not null
  • index on follower_id
  • index on following_id
  • index on [:follower_id, :following_id], unique: true
  • belongs_to user
Clone this wiki locally