S
S
SoloMidPlzD2016-11-28 18:51:18
MySQL
SoloMidPlzD, 2016-11-28 18:51:18

How to log changes with the ability to roll back?

let's say there is a simple scheme many-to-many
articles, article_tags, tags It is
necessary that each change be logged + the ability to roll back in 1-3 clicks
to change the article fields, and the tags associated with it.
Let's say there was an entry:
article.title = "hello world1", article.body = "Entry text1", article.published_at = 2016-11-20, article.user_id = 1;
article_tags binding (1,1), (1,2)
Another user modified the article and it is already
article.title = "hello world2", article.body = "Post text2", article.published_at = 2016-11-20, article. user_id = 3;
bundle article_tags (1,1), (1,3), (1,4)

Answer the question

In order to leave comments, you need to log in

6 answer(s)
U
UksusoFF, 2016-11-29
@SoloMidPlzD

https://github.com/VentureCraft/revisionable

A
Alexander Aksentiev, 2016-11-28
@Sanasol

change what?

E
Eugene Wolf, 2016-11-28
@Wolfnsex

What changes do you want to log? Databases or files? If files - then GIT.
If bases, then migrations or maybe Git+migrations.
If there is also data in the database, then backup the database (if the database is small, then backup in GIT).

A
Alexander Urich, 2016-11-28
@Urichalex

For example, keep 2 tables
currentItem
itemHistory
Before writing to currentItem its contents with a new entry in itemHistory
And rollback in the same way

S
Stanislav Pochepko, 2016-11-28
@DJZT

This raises the issue of data integrity. If you delete one of the linked objects that was used in the past, then it will no longer be possible to restore this link from the log. And so I would store everything in one table with the revision number. That is, each time I would duplicate the connection when it changes and write a global scope to select this connection.

S
Stepan, 2016-12-01
@steff

Maybe it would be more convenient to hang up a table update/change trigger that will write "old" values ​​to the "archive values ​​table"?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question