Answer the question
In order to leave comments, you need to log in
How to implement versioning of some entity in the database?
Hello.
Let's imagine a situation - we have users who fill out a questionnaire. According to the conditions, the questionnaire cannot be edited, you can only roll out a new version of the questionnaire, and the old one must be saved for history so that site owners can always track what was indicated at which step of the questionnaire.
I myself see the following options:
1) The database has a profile table, which has a status field , where you can specify whether the profile is current, new or old. Here is the schedule:
id | field | field | status
1 -- -- old
2 -- -- actual
3 -- -- new
id | field | value | version
1 name Alex 1
2 age 21 1
3 name Alexander 2
3 name Alexander Great 3
Answer the question
In order to leave comments, you need to log in
A profile is some kind of entity, and it asks to call it a document and use some kind of nosql document database.
As for your case, add the versionid in the table and stupidly copy the entire record increasing the version.
I agree it will take more space, but do not overcomplicate the scheme
Пользователь
- его профиль с датой изменения
. The current profile with the maximum date.
approves the new profileAdd a field
дата одобрения
and its maximum value. I am not a MySQL expert, but this DBMS, like almost all modern relational DBMS, supports the JSON data type. In cases like yours, I "emulate" MongoDB in a relational DBMS by creating a table with an ID field - autoincrement and a DATA field - JSON. And already in JSON add the version field and whatever.
This will also solve the problem with the new fields of the questionnaire.
You can add JSON to an existing table, or you can write a migration utility. Both ways are relatively simple.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question