Keeping a history of data changes in database

前端 未结 7 943
醉梦人生
醉梦人生 2020-12-28 21:48

Every change of data in some row in database should save the previous row data in some kind of history so user can rollback to previous row data state. Is there any good pra

7条回答
  •  -上瘾入骨i
    2020-12-28 22:36

    Saving serialized data always gets messy in the end, you're right to stay away from that. The best thing to do is to create a parallel "version" table with the same columns as your main table.

    For instance, if you have a table named "book", with columns "id", "name", "author", you could add a table named "book_version" with columns "id", "name", "author", "version_date", "version_user"

    Each time you insert or update a record on table "book", your application will also insert into "book_version".

    Depending on your database system and the way you database access from your application, you may be able to completely automate this (cfr the Versionable plugin in Doctrine)

提交回复
热议问题