Skip to content

Commit

Permalink
init_database
Browse files Browse the repository at this point in the history
  • Loading branch information
tuwq committed Apr 29, 2018
1 parent 524bc55 commit 2fe5eef
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 7 deletions.
5 changes: 5 additions & 0 deletions server/database/models/answer_user.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const mongoose = require('mongoose');
const answerUser = require('../schema/answer_user.js')
var AnswerUser = mongoose.model('AnswerUser', answerUser,'answerUser')

module.exports = AnswerUser
6 changes: 3 additions & 3 deletions server/database/models/question_user.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const mongoose = require('mongoose');
const question_user = require('../schema/question_user.js')
var Question_user = mongoose.model('Question_user', question_user,'question_user')
const questionUser = require('../schema/question_user.js')
var QuestionUser = mongoose.model('QuestionUser', questionUser,'questionUser')

module.exports = Question_user
module.exports = QuestionUser
28 changes: 28 additions & 0 deletions server/database/schema/answer_user.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const mongoose = require('mongoose')
const Schema = mongoose.Schema;
const { ObjectId, Mixed } = Schema.Types

var AnswerUserSchema = new Schema({
answer_id: {
type: ObjectId,
ref: 'Answer'
},
user_id: {
type: ObjectId,
ref: 'User'
},
vote: {
unique: false,
required: true,
type: Number,
default: 0
},
bad: {
unique: false,
required: true,
type: Number,
default: 0
}
})

module.exports = AnswerUserSchema
18 changes: 15 additions & 3 deletions server/database/schema/question_user.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const mongoose = require('mongoose')
const Schema = mongoose.Schema;
const { ObjectId, Mixed } = Schema.Types

var Question_User = new Schema({
var QuestionUser = new Schema({
question_id: {
type: ObjectId,
ref: 'Question'
Expand All @@ -12,8 +12,20 @@ var Question_User = new Schema({
ref: 'User'
},
vote: {
unique: false,
required: true,
type: Number,
default: 0
}
},
meta: {
createdAt: {
type: Date,
default: Date.now()
},
updatedAt: {
type: Date,
default: Date.now()
}
}
})
module.exports = Question_User
module.exports = QuestionUser
2 changes: 1 addition & 1 deletion server/database/表设计.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ answers: {
bad, num
created_time time
}
answers_user: {
answer_user: {
answer_id, objectid
user_id, objectid
vote, num
Expand Down

0 comments on commit 2fe5eef

Please sign in to comment.