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?
-
Good search keywords for this are ["database revisions"](http://stackoverflow.com/search?q=database+revisions), yielding a lot of relevant questions. The [top](http://stackoverflow.com/questions/39281/database-design-for-revisions) [two](http://stackoverflow.com/questions/750782/database-design-for-text-revisions) results seems to cover the area quite well. – Jørn Schou-Rode Apr 24 '10 at 09:01
2 Answers
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.

- 181,030
- 38
- 327
- 365
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.

- 1,273
- 10
- 17