E
E
Evgeny Ivanov2021-08-11 07:23:24
Database
Evgeny Ivanov, 2021-08-11 07:23:24

How to organize work with customer cards (DB) on the web?

There is a website (web application in php/python/asp) that works with a database.
The database stores data, such as medical records of clients.

The manager in the browser is loaded with such a map. And he can edit it, change his full name ...
There are a lot of managers.
As a result, if two managers simultaneously open one card and then save it, then the work of one of them will be lost. will be overwritten by the manager who saved later.

There is only one card in life. And this situation usually does not arise.
In GIT, this situation is called a conflict that needs to be resolved.
In cloud storage (for example, mail), the file is duplicated and conflicted_copy is added to its name.

How to implement it on the web?
That is, you need to make sure that when one manager opens the card, it becomes inaccessible to the second.
And when closed - available.

I have options for solving this problem (my "bikes"), but each has its drawbacks.
How to organize work with customer cards (DB) on the web? How is this done in large projects/systems, how is it done?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Gornostaev, 2021-08-11
@logpol32

Read about optimistic locks.

A
Andrew, 2021-08-11
@deepblack

How to implement it on the web?
That is, you need to make sure that when one manager opens the card, it becomes inaccessible to the second.
And when closed - available.

Add additional fields to the database table:
locked BOOLEAN
locked_user_id BIGINT
locked_at TIMESTAMP

Set the sign of blocking for the time of editing , the id of the user who blocked the record, and the time when this (blocking) happened.
For the rest at the application level, leave the ability to work with a locked record in read mode.
Add to the admin panel the ability to forcibly remove the lock, as well as periodically (on a schedule) to remove the lock.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question