Schema - alex-ciminillo/freeBook GitHub Wiki
Postgres Database Schema
users
column name | data type | details |
---|---|---|
id |
integer | not null, primary key |
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 |
first_name |
string | not null |
last_name |
string | not null |
birthday |
datetime | not null |
phone_number |
string |
- index on
email, unique: true
- index on
first_name
- index on
last_name
- index on
session_token, unique: true
has_many posts
has_many comments
posts
column name | data type | details |
---|---|---|
id |
integer | not null, primary key |
body |
string | not null |
author_id |
integer | not null, indexed, foreign key |
image_url |
string | |
created_at |
datetime | not null |
updated_at |
datetime | not null |
feeling |
string |
author_id
referencesusers
- index on
author_id
belongs_to author
comments
column name | data type | details |
---|---|---|
id |
integer | not null, primary key |
body |
string | not null |
author_id |
integer | not null, indexed, foreign key |
post_id |
integer | not null, indexed, foreign key |
created_at |
datetime | not null |
updated_at |
datetime | not null |
author_id
referencesusers
post_id
referencesposts
- index on
author_id
- index on
post_id
belongs_to author
belongs_to post
friends
column name | data type | details |
---|---|---|
id |
integer | not null, primary key |
second_user_id |
integer | not null, indexed, foreign key |
first_user_id |
integer | not null, indexed, foreign key |
created_at |
datetime | not null |
updated_at |
datetime | not null |
second_user_id
referencesusers
first_user_id
referencesusers
- index on
[:second_user_id, :first_user_id], unique: true
- index on
[:first_user_id, :second_user_id], unique: true
belongs_to user