views:

47

answers:

2

I need to make article that cannot be edited, but it can be saved as a new version and only the newest version is shown to users. How should I implement this kind of database design?

A: 

There are a couple of ways to handle this. I think the most straight forward way is to have a table, "article", with whatever data is set in stone when the article is created (id for example) and a second table with each edited version, "articleVersion". article would have a one to many relationship with articleVersion.

You could set a bit, "currentVersion", and toggle it off on old version and on for the new version. You could also just use a datetime, "dateCreated", to get the newest version since you never plan on editing them.

Felan
+2  A: 

The database can have a version number or timestamp on each version of the article, and you just serve up the most recent article (highest version number or most recent timestamp).

For best results, use a reverse proxy cache to avoid touching the database on every hit.

Marcelo Cantos
Definitely better than currentVersion or dateCreated that I suggested.
Felan