T
T
tjfwapjfa2018-03-03 16:26:35
MySQL
tjfwapjfa, 2018-03-03 16:26:35

How to store versions of texts?

Let's say I need to store versions of texts. I'm guessing this:
texts
- id
- author_id
...
versions
- id
- text_id
- text
Note that I don't store text in the text table, only in versions. When creating a new text, I also create a new version and save the text there. Right move?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
R
res2001, 2018-03-03
@tjfwapjfa

You can organize versioning based on one table, just add a field with a timestamp to the table. When changing, we simply add a new record with a new timestamp. To select the current record, select the record with the highest timestamp. An interface for viewing changes, etc. is easily made.
To delete, you need to create a status field where the sign of deletion will be written, do not physically delete the records.
I have repeatedly seen a similar scheme of tables with history in banking software.

A
AVKor, 2018-03-03
@AVKor

You can store patches. If the text sizes are large and there are a lot of them, then the space will be spent more economically. But to restore the full text of a certain version in this case, it is necessary to patch the original version the required number of times.

A
Andrey Sanych, 2018-03-03
@mountpoint

Yes

Z
Zakharov Alexander, 2018-03-03
@AlexZaharow

You can hang a trigger on the change, add, delete events so as not to program all the business logic. From the trigger it is possible to write though in the next column, though in the next table.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question