Effective management of data changes

后端 未结 5 1110
滥情空心
滥情空心 2021-02-13 18:05

I have a table called Bookings. This table contains data representing a booking made for a particular service, with many variables.

A while ago I came across a problem w

5条回答
  •  -上瘾入骨i
    2021-02-13 18:50

    It seems to me, what you need is a kind of history of a table so that you are able to know what happen in the time.

    I usually achieve such an approach by creating a parallel table called like the original appending _history to it. Bookings_history in your case. The structure would be similar to the original but prepending the columns:

    a) timestamp, that save when the modification happened

    b) id, to identify the row in the original table

    A unique index on this two columns would be created.

    Each time a modification happens, before applying the modification you copy the original row to the history table. Then you apply the modification on the original table. Doing so, the history table acts like a stack where you save snapshots of the original data.

    I specially like this model because joining tables and applying search engines on the history table can be done in a similar way as you did for the original table, because the structure is quite similar. Also, if you want to know about modifications, you just need to compare rows of the history table.

    I hope this helps.

提交回复
热议问题