schema - Patrick-Mondala/facebook-clone GitHub Wiki
Database Schema
users
| column name | data type | details |
|---|---|---|
id |
integer | not null, primary key |
first_name |
string | not null |
last_name |
string | not null |
email |
string | not null, indexed, unique |
password_digest |
string | not null |
session_token |
string | not null, indexed, unique |
birth_date |
datetime | not null |
gender |
string | not null |
bio |
string | |
location |
string | |
current_city |
string | |
hometown |
string | |
workplace |
string | |
education |
string | |
created_at |
datetime | not null |
updated_at |
datetime | not null |
- index on
email,unique: true - index on
session_token,unique: true
friendships
| column name | data type | details |
|---|---|---|
id |
integer | not null, primary key |
requester_id |
integer | not null, indexed |
requested_id |
integer | not null, indexed |
accepted |
boolean | not null |
created_at |
datetime | not null |
updated_at |
datetime | not null |
- index on
requester_iduserwho created friend request
- index on
requested_iduserwho received friend request
- index on
[requester_id, requested_id], unique: true
posts
| column name | data type | details |
|---|---|---|
id |
integer | not null, primary key |
author_id |
integer | not null, indexed |
timeline_owner_id |
integer | not null, indexed |
body |
string | |
created_at |
datetime | not null |
updated_at |
datetime | not null |
- index on
author_iduserwho createdpost
- index on
timeline_owner_iduserwho owns the timeline thepostwas posted on
tags
| column name | data type | details |
|---|---|---|
id |
integer | not null, primary key |
post_id |
integer | not null, indexed |
tagger_id |
integer | not null, indexed |
tagged_user_id |
integer | not null, indexed |
created_at |
datetime | not null |
updated_at |
datetime | not null |
- index on
post_idpostthetagwas made on
- index on
tagger_iduserthattaggedanotheruser
- index on
tagged_user_iduserthat wastagged
comments
| column name | data type | details |
|---|---|---|
id |
integer | not null, primary key |
body |
string | |
author_id |
integer | not null, indexed |
post_id |
integer | not null, indexed |
parent_comment_id |
integer | indexed |
created_at |
datetime | not null |
updated_at |
datetime | not null |
- index on
author_iduserwho createdcomment
- index on
post_idpostthecommentwas made on
- index on
parent_comment_idcommentthat the newcommentwas made on