-
Notifications
You must be signed in to change notification settings - Fork 1
Database Schema
Wei-Yang Lin edited this page Sep 20, 2021
·
10 revisions
* "database": "mora_development"
* "username": "mora_development_app",
* "password": "password",
* categories
* users
* questions
* questions_categories
* answers
* comments
| column name | data type | details |
|---|---|---|
| id | int | pk, not null, unique |
| user_name | varchar(50) | not null, unique |
| varchar(255) | not null, unique | |
| occupation | varchar(100) | |
| hashed_password | varchar(255) | not null |
| created_at | timestamp | not null |
| updated_at | timestamp | not null |
| column name | data type | details |
|---|---|---|
| id | int | pk, not null, unique |
| user_id | int | fk, references users table(id), not null |
| title | text | not null, max length 1000 |
| created_at | timestamp | not null |
| updated_at | timestamp | not null |
- user_id is foreign key, references user table(id), relation is one to many
- One question belongs to one user
- One user has many questions
| column name | data type | details |
|---|---|---|
| id | int | pk, not null, unique |
| user_id | int | fk, references users table(id), not null |
| question_id | int | fk, references questions table(id), not null |
| content | text | not null |
| created_at | timestamp | not null |
| updated_at | timestamp | not null |
- user_id is foreign key, references user table(id), relation is one to many
- One answer belongs to one user
- One user has many answers
- question_id is foreign key, references question table(id), relation is one to many
- One answer belongs to one question
- One question has many answers
| column name | data type | details |
|---|---|---|
| id | int | pk, not null, unique |
| user_id | int | fk, references users table(id), not null |
| question_id | int | fk, references questions table(id), not null |
| created_at | timestamp | not null |
| updated_at | timestamp | not null |
- user_id is foreign key, references user table(id), relation is one to many
- One vote belongs to one user
- One user has many votes
- question_id is foreign key, references question table(id), relation is one to many
- One vote belongs to one question
- One question has many votes
| column name | data type | details |
|---|---|---|
| id | int | pk, not null, unique |
| user_id | int | fk, references users table(id), not null |
| answer_id | int | fk, references answers table(id), not null |
| created_at | timestamp | not null |
| updated_at | timestamp | not null |
- user_id is foreign key, references user table(id), relation is one to many
- One vote belongs to one user
- One user has many votes
- answer_id is foreign key, references answer table(id), relation is one to many
- One vote belongs to one answer
- One answer has many votes
| column name | data type | details |
|---|---|---|
| id | int | pk, not null, unique |
| answer_id | int | fk, references answers table(id), not null |
| user_id | int | fk, references users table(id), not null |
| content | text | not null |
| created_at | timestamp | not null |
| updated_at | timestamp | not null |
- user_id is foreign key, references user table(id), relation is one to many
- One comments belongs to one user
- One user has many comments
- answer_id is foreign key, references answers table(id), relation is one to many
- One comment belongs to one answer
- One answer has many comments
| column name | data type | details |
|---|---|---|
| id | int | pk, not null, unique |
| name | enum | not null |
| created_at | timestamp | not null |
| updated_at | timestamp | not null |
- enum data type please reference here
- category_list = [drama, horror, action, romance, thriller, documentary, reality shows ,science fiction, comedy , other]
| column name | data type | details |
|---|---|---|
| id | int | pk, not null, unique |
| question_id | int | fk, references questions table(id), not null |
| category_id | int | fk, references categories table(id), not null |
| created_at | timestamp | not null |
| updated_at | timestamp | not null |
- This is a join table, define the relationship between questions and categories is many to many
- Question.belongsToMany(Category, { through: "questions_categories foreignKey: "question_id", otherKey: "category_id" });
- Category.belongsToMany(Question, { through: "questions_categories", foreignKey: "category_id", otherKey: "question_id" });