D
D
DDwrt1002020-08-19 17:58:04
Database design
DDwrt100, 2020-08-19 17:58:04

How to organize chains of approvers to approve a document?

Good afternoon. Can anyone suggest how this functionality is implemented?
The question is rather abstract, but for specifics, let it be the Postgress database.
Functional. There is a document, there is a person who generates the content of this document, and there are approvers who are determined during the creation of the document, the list of approvers is variable, there may be two people, or maybe 10.

From the functional part, it looks like this, through the UI, press "create document" an empty form is displayed with fields that need to be filled in, one of the fields is matching, people are added to this field using the directory.

Actually, the question itself is, what structure should the database have in order to implement a variable list of matchers?
Everything is clear from the documents, define the fields to be changed and store them in a separate table. But the non-deterministic list is not yet entirely clear. Who can tell how this is implemented by relational databases.
Or is it definitely necessary to look into Nosql like mongo ?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
I
Ivan Shumov, 2020-08-19
@DDwrt100

Let's separate the data structure from the business logic. We need to keep separate documents and a separate list of signatories of this document. These are 2 different tables. For beauty, we can add a third - users, but not at all necessary (this table is only in monoliths).
The signature table can contain links to the document, user, signed status (bool) and various service information. If necessary, you can add a signature stage, mandatory (required: bool) or whatever else may be required. The fact of approval can be stored both in the document and in a separate table (if there are several stages of signing).
And the business logic is already deciding how to calculate the fact of approval of the document based on this data

A
Alexander, 2020-08-19
@NeiroNx

Most likely, the levels of the coordinators (reflecting their subordination) - the main one will not sign until all the intermediate bosses have signed.
Coordinators of the same level are unlikely to meet, and if they do, then the order will not matter.

S
Station 72, 2020-08-19
@cjstress

Dig towards the FSM pattern. There are document states, there are necessary approvers. Agreed - go to the next state.

X
xmoonlight, 2020-08-19
@xmoonlight

First, we determine the list of positions of the approvers and sort them by seniority: from the minimum influence of the signature to the maximum (to the oldest approver).
And we write in the table cell in the form of json data with the id-s of all the matching ones.
Then, we consider the result of full matching:
T=A1*2^0+...+AN*2^(n-1),
where
N is the sequence number by precedence,
A1..AN is the fact of matching by each of the chain: 1 - agreed, 0 - no.
And we write the current match value and the target match value to the same row in the database.
When the difference is equal to 0, the document will be fully approved by the entire chain of people.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question