简体   繁体   English

申请批准数据库模型

[英]Request approval database model

I have a question regarding an efficient way of modeling the following scenario: 我有一个关于以下场景建模的有效方法的问题:

We have a "Request" which can have the following states: 我们有一个“请求”,它可以具有以下状态:

  • pending 待定
  • approved 已批准
  • rejected 被拒绝
  • cancelled 取消

A request is issued by a user and can be approved/rejected by one or more users (with a higher role). 一个请求由用户发出,并且可以被一个或多个用户(具有较高角色)批准/拒绝。 There are certain rules that decide to which user should the request be assigned for approval and only if all in the respective list approve it can be really approved. 有某些规则决定应将请求分配给哪个用户批准,并且只有在相应列表中的所有请求都被批准后才能真正批准。

I have a Request table with the necessary info, and a User table at the moment. 我现在有一个带有必要信息的Request表和一个User表。 I have to save the following info: the users that need to approve the request and how they "voted". 我必须保存以下信息:需要批准请求的用户以及他们如何“投票”。

How can I design this in an efficient way? 如何有效设计?

Thank you 谢谢

I would use a table votes with columns request_id , user_id and vote . 我将使用带有表request_iduser_idvote的表votes

When a new request is created, insert for each user who has to approve it one row in votes like (new_request_id, approver_id, 0). 当创建一个新的请求时,插入谁有权批准它每行显示一个用户votes样(new_request_id,approver_id,0)。

When a user approves, set vote to 1. If a user rejects, set it to -1. 用户批准后,将vote设置为1。如果用户拒绝,则将vote设置为-1。 This way 0 means "no vote yet". 这样,0表示“尚无投票”。

You also could use two tables, one for votes and one for needed approvers. 您还可以使用两个表格,一个用于投票,一个用于需要的批准者。 But I don't see a great advantage. 但是我看不到很大的优势。 And of course you could add a column for the timestamp of the vote if you need it. 当然,如果需要,您可以为投票的时间戳添加一列。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM