views:

75

answers:

4

i am wondering how can i have simple versioning, say i want to be able to undo past edits (just up to 3 will do) to a post. maybe because the app allows other user to edit a post. but i may want the owner to restore the post for example.

do i just store the full post in another field?

+2  A: 

One suggestion could be something like this:

you propably have each post as a separate row in the table and it has indexes that point to right threat and you retain their order by those indexes.

Add a "revision" to each post row. Everytime user edits the post, you store a new row into table but with higher revision. And when showing the posts, you just fetch the one with highest revision..

rasjani
this is one way, then i guess i also can setup a automated job to clear old revisions
jiewmeng
Yep, that would be the way.
rasjani
+1  A: 

I've done this previously by creating a table which contains the following columns: id, serialisation value of entire row you want backed up, the table it is for, datetime, why the backup was created.

That way you have a complete listing of all the versions of that table. I use Doctrine ORM so that way I can setup a postSave hook to create a new backup version in that table.

balupton
`postUpdate` in doctrine 2 :)
jiewmeng
A: 

It is not exactly what you want, but here is a good article on versioning data in database: http://www.jasny.net/articles/versioning-mysql-data/

FractalizeR
A: 

Doctrine Versionable Bebaviour may be the simplest solution for you:

Doctrine - Doctrine ORM for PHP - Versionable

takeshin