Schema - nicolaspiper/Instakilogram GitHub Wiki
Users
| column name | data type | details |
|---|---|---|
id |
integer | not null, primary key |
username |
string | not null, indexed, unique |
name. |
string | not null |
website |
string | optional, unique |
birthday |
date | not null |
bio |
text | optional |
email |
string | not null, indexed, unique |
password_digest |
string | not null |
session_token |
string | not null, indexed, unique |
created |
datetime | not null |
updated |
datetime | not null |
- Index on
username, unique: true - Index on
email, unique: true - Index on
session_token, unique: true - Including
birthday, presence: trueat model level to enforce age restrictions emailwill be validated with Regex at the model level
Users associations
has_many :postshas_many :commentshas_many :tagshas_many :taggedhas_many :post_likeshas_many :comment_likes
Posts
| column name | data type | details |
|---|---|---|
id |
integer | not null, primary key |
caption |
string | optional |
author_id |
integer | not null, indexed, foreign key |
created |
datetime | not null |
updated |
datetime | not null |
- Index on
author_id, unique: true author_idis keyed to a user'sid
Posts associations
belongs_to :userhas_many :hashtagshas_many :tagshas_many :post_likeshas_many :comments
Post_likes
| column name | data type | details |
|---|---|---|
id |
integer | not null, primary key |
user_id |
integer | not null, indexed, foreign key |
post_id |
integer | not null, indexed, foreign key |
created |
datetime | not null |
updated |
datetime | not null |
- Index on
[:user_id, :likable_id]for faster recall - Joins table for likes
Post_like associations
belongs_to :userbelongs_to :post
Comments
| column name | data type | details |
|---|---|---|
id |
integer | not null, primary key |
body |
text | not null |
user_id |
integer | not null, indexed, foreign key |
post_id |
integer | not null, indexed, foreign key |
created |
datetime | not null |
updated |
datetime | not null |
- indexed on
[:photo_id] - indexed on
[:post_id]
Comments associations
belongs_to :userbelongs_to :posthas_many :likes
Comment_likes
| column name | data type | details |
|---|---|---|
id |
integer | not null, primary key |
user_id |
integer | not null, indexed, foreign key |
comment_id |
integer | not null, indexed, foreign key |
created |
datetime | not null |
updated |
datetime | not null |
- Index on
[:user_id, :likable_id]for faster recall - Joins table for likes
Comment_likes
belongs_to :userbelongs_to :comment
Follows
| column name | data type | details |
|---|---|---|
id |
integer | not null, primary key |
followed_id |
integer | not null, indexed, foreign key |
follower_id |
integer | not null, indexed, foreign key |
created |
datetime | not null |
updated |
datetime | not null |
- Joins table for follows
Follows associations
belongs_to :followerbelongs_to :followed
Bonus features
Tags
| column name | data type | details |
|---|---|---|
id |
integer | not null, primary key |
tagged_id |
integer | not null, foreign key |
tagger_id |
integer | not null, foreign key |
tagsare universal and don't have any "scope" users are notified and link-able on posts and comments through tags
Post_hashtag
| column name | data type | details |
|---|---|---|
id |
integer | not null, primary key |
hashtag_id |
integer | not null, indexed, foreign key |
post_id |
integer | not null, indexed, foreign key |
Comment_hashtag
| column name | data type | details |
|---|---|---|
id |
integer | not null, primary key |
hashtag_id |
integer | not null, indexed, foreign key |
post_idanalog is not required as Instagram does not seem to display posts with hashtags in their comments to their respective hashtag page