Effective management of data changes

后端 未结 5 1102
滥情空心
滥情空心 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:42

    From the answers you gathered already it's pretty apparent that whatever you do, it will require some or more redesign.

    One of the solutions I don't see yet and that I've used in the past to solve such problems (i.e. orders that are changed) is to keep everything in the same table and use field(s) to differentiate them.

    You can change the bookings table to add an incremented integer per booking (i.e. version_number) and a is_latest field. This way you can query with is_latest=true to get the current record and its version_number. If it is 0, there were no changes, if it is >0 then there are changes (that number will equal the number of changes). You will be able to "rewind" or "replay" the history if you go from latest version to 0 or the opposite way round and each time you'll be having a complete record that your app understands without modifications.

    If is_latest is indexed the querying speed will (almost) equal the original table querying speed and of course you can add more booleans like is_original if you need to get the original booking many times.

    This has the benefit that it will most probably require you to change only the Booking model but that will depend on your code.

    EDIT: I believe that this approach will be most compatible with your requirement about reporting and financial record as you will always have the original record (version 0) easily available.

提交回复
热议问题