Skip to content

Database Schema

Aaron Agarunov edited this page Dec 28, 2017 · 8 revisions

users

Column Name Data Type Constraints
id integer not null, pkey
username string not null, index, unique
password_digest string not null
session_token string not null, index, unique
profile_photo string
bio text
location string
created_at datetime not null
updated_at datetime not null
  • profile_photo is a custom upload that isn't available for editing or viewing on the user's profile, but can be replaced by uploading another profile photo

photos

Column Name Data Type Constraints
id integer not null, pkey
author_id integer not null, index, fkey
photo_url string not null
title string
description text
is_cover_photo boolean default: false, unique for author_id
created_at datetime not null
updated_at datetime not null
  • author_id references users
  • when is_cover_photo is true, the author_id is using the photo as their cover photo
    • a user has_one cover_photo -> { where is_cover_photo: true } (has_one scoping)

follows

Column Name Data Type Constraints
id integer not null, pkey
follower_id integer not null, index, fkey
followee_id integer not null, index, fkey
created_at datetime not null
updated_at datetime not null
  • follower_id and followee_id reference users
  • unique index on follower_id and followee_id

likes

Column Name Data Type Constraints
id integer not null, pkey
author_id integer not null, index, fkey
photo_id integer not null, index, fkey
created_at datetime not null
updated_at datetime not null
  • author_id references users
  • photo_id references photos
  • unique index on author_id and photo_id

Bonus

tags

Column Name Data Type Constraints
id integer not null, pkey
name string not null, unique
created_at datetime not null
updated_at datetime not null

taggings

Column Name Data Type Constraints
id integer not null, pkey
photo_id integer not null, index, fkey, unique
tag_id integer not null, index, fkey, unique
created_at datetime not null
updated_at datetime not null
  • unique index on tag_id and photo_id
  • index on photo_id
Clone this wiki locally