Ski*_*ᴉʞS 7 mysql database postgresql database-design entity-relationship
我在这里看到很多问题,但没有人适应我的问题.我正在尝试创建一个可扩展的ER模型,如果我想添加更多数据,几乎不会破坏任何东西,所以我试图创建的是:
有两种类型的用户,比如Admin和Worker,他们有不同的角色.
管理员可以做一个问题的CRUD,也可以创建一个用户可以加入一起玩的房间(这只是一个名字,像Kahoot!那样)但也许在其中创建更多属性是个好主意,比如世界卫生组织正在这个房间里玩,每个人都要点,但是当我向你展示设计时,让我们再谈谈它.
好吧,就我的设计而言,我有:
表用户包含:
_id
username
password
date_creation
Run Code Online (Sandbox Code Playgroud)
这是一个默认的,但是我想知道如何定义角色,如果它是管理员或工人,比如isAdmin:true然后我检查这个Bool?或者我可以创建另一个角色表并将其连接到用户表?
但也许我必须为两者创建一个表,我的意思是有一个管理员,它有一个密码和一些功能,然后使用户工具有另一个密码和其他功能.
然后我想让问题表包含:
_id
question_name
answers[1,2,3,4]
correctAnswer or answers because it can be multi option chooser
topic
isExamQuestion
dificulty
Run Code Online (Sandbox Code Playgroud)
那么Room表应该包含:
_id
name
capacity
type (game can be as a group or solo) that's why this attribute
exam (This should be a flag to know if this question is for an exam or not (It can be for EXAM or PRACTISE)
ranking (This is the top X from 1 to X)
don't think if I have to add the winner here because if I get the position 0 from ranking I get the winner...
Run Code Online (Sandbox Code Playgroud)
还有一个名为Topic的表,如果我的问题有主题,那么我可以按主题选择问题.主题的一个示例应该是Math,因此用户只能进行考试或使用数学问题进行测试.
_id
Name
Questions[...]
Then I have to store like a historic about what are the questions worker has answered correct and what did not, to make some statistics, but I need to store some historicals for Admin to see in this topic the average that Workers have failed more is : Question23 (for instance) something like that.
Run Code Online (Sandbox Code Playgroud)
我错过了什么,你能不能帮我弄明白如何让这个设计变得更好?
注意:我使用Spring作为服务器端,Angular作为Frontend的东西,以及Android for App,我可以使用此数据库更改任何内容以更快/更好地工作.
如果你需要更多的细节,如果我被解释错了,游戏的流程就会出现.
管理流程
工人流是
他可以练习意味着他随机或按主题回答问题(每个答案都应该保存用于统计,并避免重复他的责任更正),他也可以做考试(不是多人)只是管理员可以检查是否问题是考试的一部分.
然后房间的东西,他可以加入Id.
如果您需要进一步说明,请告诉我,我会尽快回复您.
实际上,您的系统有三个逻辑部分(模块):
用户模块:
role - 包含系统中的用户角色
user - 包含用户和分配给他们的角色信息
问卷调查:
主题 - 包含问题主题
问题 - 包含问题
回答 - 包含所有问题的答案
房间 - 包含有关房间的信息
user_in_room - 包含有关加入房间的用户的信息
历史模块:
user_question_history - 包含有关用户回答的问题的信息
user_answer_history - 包含有关用户选择的答案的信息
使用此模式可以构建不同的报告.例如,您可以按房间显示所有用户的结果
SELECT r.id,
r.name,
u.username,
ur.score
FROM room as r
LEFT JOIN user_in_room as ur ON ur.room_id = r.id
LEFT JOIN user as u ON u.id = ur.user_id
WHERE r.id = <id>
Run Code Online (Sandbox Code Playgroud)
或者,您可以查看有关用户答案的详细信息
SELECT
q.text,
a.text
FROM user_in_room as ur ON ur.room_id = r.id
LEFT JOIN user_question_history as uqh ON ugh.user_id = ur.user_id AND ugh.root_id = ur.room_id
LEFT JOIN question as q ON q.id = ugh.question_id
LEFT JOIN user_answer_history as uah ON uah.user_id = ugh.user_id AND uah.room_id = ugh.room_id AND uah.question_id = ugh.question_id
LEFT JOIN answer as a ON a.id = uah.answer_id
WHERE ur.room_id = <id> AND ur.user_id = <id>
Run Code Online (Sandbox Code Playgroud)