Schema - brjohn/Friendbook GitHub Wiki

Postgres Database Schema

users

Column Name Data Type Details
id integer not null, primary key
first_name string not null
last_name string not null
birthday date not null
gender string not null
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
bio text
work string
education string
current_city string
hometown string
relationship string
name_pronunciation string
  • index on email, unique: true
  • index on session_token, unique: true

friendships

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

requests

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

posts

Column Name Data Type Details
id integer not null, primary key
poster_id integer not null, indexed, foreign key
wall_owner_id integer not null, indexed, foreign key
body string
created_at datetime not null
updated_at datetime not null
  • poster_id references users
  • wall_owner_id references users
  • index on poster_id
  • index on wall_owner_id

comments

Column Name Data Type Details
id integer not null, primary key
commenter_id integer not null, indexed, foreign key
post_id integer not null, indexed, foreign key
body string not null
created_at datetime not null
updated_at datetime not null
  • commenter_id references users
  • post_id references posts
  • index on commenter_id
  • index on post_id

likes

Column Name Data Type Details
id integer not null, primary key
likeable_id integer not null, indexed, foreign key
likeable_type string not null, indexed
created_at datetime not null
updated_at datetime not null
  • likeable_id references a polymorphic association to posts or comments
  • index on likeable_id
  • index on likeable_type