Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keeping page changes history. A bit like SO does for revisions

I have a CMS system that stores data across tables like this:

Entries Table
+----+-------+------+--------+--------+
| id | title | text | index1 | index2 |
+----+-------+------+--------+--------+

Entries META Table
+----+----------+-------+-------+
| id | entry_id | value | param |
+----+----------+-------+-------+

Files Table
+----+----------+----------+
| id | entry_id | filename |
+----+----------+----------+

Entries-to-Tags Table
+----+----------+--------+
| id | entry_id | tag_id |
+----+----------+--------+

Tags Table
+----+-----+
| id | tag |
+----+-----+

I am in trying to implement a revision system, a bit like SO has. If I was just doing it for the Entries Table I was planning to just keep a copy of all changes to that table in a separate table. As I have to do it for at least 4 tables (the TAGS table doesn't need to have revisions) this doesn't seem at all like an elegant solution.

How would you guys do it?

Please notice that the Meta Tables are modeled in EAV (entity-attribute-value).

Thank you in advance.

like image 728
Frankie Avatar asked Aug 14 '10 00:08

Frankie


People also ask

Why do you need a document revision history table?

A document revision history table will save you a lot of headaches when it is time to send out your document for review. Reviewers, especially in hi-tech companies, are very busy people. They are usually SME (Subject Matter Expert) engineers, developers, product managers or the client who hired you to draft the document.

How do I Find my revision history in WordPress?

How to Use Your WordPress Revision History. As you can see from the screenshot below, Revisions shows up in the Publish section on the post editing screen. You can also display revisions below the post editor by clicking Screen Options and ticking the box next to Revisions. When you click the Browse link, you’ll be taken to the Revisions screen.

How do I view changes made in a revision?

When you click the Browse link, you’ll be taken to the Revisions screen. Here, you can see the changes that were made in each revision by dragging the slider at the top of the screen. You can also use the Previous and Next buttons, as well as compare any two revisions by checking the box above.

How do you keep track of revisions in a document?

Include a link to any other files that were changed during that particular revision so you can find them quickly if needed. Keeping track of the revisions you’ve made to a frequently updated technical or business document is important in documentation business.


1 Answers

Hi am currently working on solution to similar problem, I am solving it by splitting my tables into two, a control table and a data table. The control table will contain a primary key and reference into the data table, the data table will contain auto increment revision key and the control table's primary key as a foreign key.

taking your entries table as an example

Entries Table
+----+-------+------+--------+--------+
| id | title | text | index1 | index2 |
+----+-------+------+--------+--------+

becomes

entries             entries_data
+----+----------+   +----------+----+--------+------+--------+--------+
| id | revision |   | revision | id |  title | text | index1 | index2 |
+----+----------+   +----------+----+--------+------+--------+--------+

to query

select * from entries join entries_data on entries.revision = entries_data.revision;

instead of updating the entries_data table you use an insert statement and then update the entries table's revision with the new revision of the entries table.

The advantage of this system is that you can move to different revisions simply by changing the revision property within the entries table. The disadvantage is you need to update your queries. I am currently integrating this into an ORM layer so the developers don't have worry about writing SQL anyway. Another idea I am toying with is for there to be a centralised revision table which all the data tables use. This would allow you to describe the state of the database with a single revision number, similar to how subversion revision numbers work.

like image 144
ejrowley Avatar answered Nov 09 '22 03:11

ejrowley