Database Schema - dmurchison/stuck_overclone_app GitHub Wiki
PostgreSQL Database Tables 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 comments
has_many votes
questions
column name | data type | details |
---|---|---|
id |
integer | not null, primary key |
title |
string | not null |
body |
text | not null |
author_id |
integer | not null, indexed, foreign key |
created_at |
datetime | not null |
updated_at |
datetime | not null |
author_id
referencesusers
parent_question_id
referencesquestions
- index on
author_id
- index on
parent_question_id
belongs_to author
has_many answers
has_many comments
has_many votes
answers
column name | data type | details |
---|---|---|
id |
integer | not null, primary key |
body |
text | 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
referencesusers
question_id
referencesquestions
- index on
[:question_id, :author_id], unique: true
belongs_to author
belongs_to question
has_many comments
has_many votes
comments
column name | data type | details |
---|---|---|
id |
integer | not null, primary key |
body |
text | not null |
commenter_id |
integer | not null, indexed, foreign key |
question_id |
integer | not null, indexed, foreign key |
answer_id |
integer | not null, indexed, foreign key |
parent_comment_id |
integer | indexed, foreign key |
created_at |
datetime | not null |
updated_at |
datetime | not null |
commenter_id
referencesusers
question_id
referencesquestions
answer_id
referencesanswers
parent_comment_id
referencescomments
index
oncommenter_id
belongs_to question
belongs_to answer
belongs_to comment
has_many comments
votes
column name | data type | details |
---|---|---|
id |
integer | not null, primary key |
voter_id |
integer | not null, indexed, foreign key |
question_id |
integer | not null, indexed, foreign key |
answer_id |
integer | not null, indexed, foreign key |
vote |
boolean | not null |
created_at |
datetime | not null |
updated_at |
datetime | not null |
voter_id
referencesusers
question_id
referencesquestions
answer_id
referencesanswers
vote
istrue
for an upvote andfalse
for a downvote- index on
[:voter_id, :question_id, :answer_id], unique: true
belongs_to user
belongs_to question
belongs_to answer