Schema - dmurchison/stuck_overclone_app Wiki

Postgres Database Schema

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 questions
  • has_many answers
  • has_many upvotes
  • has_many downvotes

questions

column name data type details
id integer not null, primary key
body string not null
code string not null
author_id integer not null, indexed, foreign key
created_at datetime not null
updated_at datetime not null
  • author_id references users
  • index on author_id
  • belongs_to user
  • has_many answers

answers

column name data type details
id integer not null, primary key
body string not null
code string not null
author_id integer not null, indexed, foreign key
question_id integer not null, indexed, foreign key
created_at datetime not null
updated_at datetime not null
  • author_id references users
  • question_id references questions
  • index on [:question_id, :author_id], unique: true
  • belongs_to question
  • belongs_to user
  • has_many upvotes
  • has_many downvotes

upvotes

column name data type details
id integer not null, primary key
user_id integer not null, indexed, foreign key
answer_id integer not null, indexed, foreign key
created_at datetime not null
updated_at datetime not null
  • user_id references users
  • answer_id references answers
  • index on [:answer_id, :user_id], unique: true
  • belongs_to answer
  • belongs_to user

downvotes

column name data type details
id integer not null, primary key
user_id integer not null, indexed, foreign key
answer_id integer not null, indexed, foreign key
created_at datetime not null
updated_at datetime not null
  • user_id references users
  • answer_id references answers
  • index on [:answer_id, :user_id], unique: true
  • belongs_to answer
  • belongs_to user