Database Schema - griffinsharp/kicker GitHub Wiki

users

Column Name Data Type Details
id integer not null, primary key
username string not null, indexed, unique
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
  • index on username, unique: true

  • index on email, unique: true

  • index on session_token, unique: true

  • has_many :projects (created a project)

  • has_many :backings (contributed to a project)

  • has_many :rewards through :backings (reward from contributing to a project)

projects

Column Name Data Type Details
id integer not null, primary key
title string not null, indexed, unique
sub_title string not null
total_pledged integer not null
goal_amount integer not null
num_backers integer not null
days_left integer not null
loved boolean
location string not null
campaign text not null
about text not null
category_id integer not null, indexed, foreign key
user_id integer not null, indexed, foreign key
created_at datetime not null
updated_at datetime not null
  • index on :title, unique: true

  • index on :category_id (refers to categories table)

  • index on :user_id (refers to users table)

  • belongs_to :user (creator)

  • belongs_to :category

  • has_many :backings

  • has_many :rewards

  • has_many :backers (users) through backings

backings

Column Name Data Type Details
id integer not null, primary key
user_id integer not null, indexed, foreign key
reward_id integer not null, indexed, foreign key
project_id integer not null, indexed, foreign key
created_at datetime not null
updated_at datetime not null
  • index on user_id (refers to users table)

  • index on reward_id (refers to rewards table)

  • index on project_id (refers to projects table)

  • indexed on [user_id, reward_id], unique: true (one reward linked to user that backed a project)

  • belongs_to :user (backer)

  • belongs_to :reward

  • has_one :project through :reward (project_id in rewards)

categories

Column Name Data Type Details
id integer not null, primary key
category_name string not null, indexed
  • index on category_name (refers to categories table)

  • has_many :projects

rewards

Column Name Data Type Details
id integer not null, primary key
amount integer not null
desc text not null
subdesc text
delivery string not null
shipping string
num_backers integer not null
project_id integer not null, indexed, foreign key
created_at datetime not null
updated_at datetime not null
  • index on project_id (refers to projects table)

  • belongs_to :project