简体   繁体   中英

What is the best way to store change history of website articles?

Our client wants us to implement change history for website articles. What is the best way to do it?

Without knowing too much about your particular application stack (framework, language), you have at least two basic approaches:

  • Versioned Records - Instead of storing articles as a single row in a database (or single file in a filesystem) and updating with changes, simply create a new record with a pointer to its previous versions. If you're on Rails, you might want to check out this Railscast about Model Versioning

  • Sequential diffs - Another approach is to keep a current copy of the document, but maintain a history of edits made by users. If it's a simple text document, these edits can be represented by a diff patch. Wikipedia "diff" for more information.

If you still need help, tell me more about your setup / requirements, and we can figure it out from there.

I presume you're using a CMS. If not, use one. WordPress is a good start.

If you're developing from scratch, the usual method is to have two tables: one for page information (so title, menu position etc.) and then a page_content table, which has columns for page_id , content , and timestamp .

As you save a page, instead of updating a database table you instead write a new record to the page_content table with the page's ID and the time of the save. That way, when displaying pages on your front-end you just select the latest record for that particular page ID, but you also have a history of that page by querying for all records by page_id , sorted by timestamp .

There is a wide variety of ways to do this as you alluded by tagging php, .net, python, and ruby. You missed a few off the top of my head perl and jsp. Each of these have their plusses and minuses and is really a question of what best suits your needs. PHP is probably the fastest reward for time spent. Ruby, i'm assuming Ruby on Rails, is the automatic Buzz Word Bingo for the day. .Net, are you all microsoft every where and want easy integration with your exchange server and a nice outlook API? python? Do you like the scripted languages but you're too good for php and ruby.

Each of these languages have their strong points and their draw backs and it's really a matter of what you know, how much you have to spend, and what is your timeframe.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM