I have to store data like articles into a mysql database and if an article is modified, I have to save the old version as well to make it possible to restore it. I have found some similar questions and posts on this topic, but I am not sure, which solution is the best to solve the problem.
Here is the basic table "articles" for better understanding:
articles (id, name, text)
For me, there are two different approaches for this:
Approach 1
Store the data and every version of an article in the table "articles" and add the columns "version" and "status". In version i store the incremented version number of the article. The active article gets the "status" 1 and the others the "status" 2.
Pro's:
Only one table is needed
A new version is an insert of the new data and only an update of the "status"-column of the old one
Con's
- Very large tables (maybe slower queries???)
Approach 2
Add the field "version" to "articles" and store only the active data into the table "articles". Old versions of the data is stored / moved to the new table "articles_versioned".
Pro's:
- Only the actual valid data is in the table "articles"
Con's
- Dublication of tables
So. Have I forgotten a good aproach? How to deal with related data in other tables (like images, etc.)?