views:

34

answers:

2

Should I clone the entire product along with all related data into another table for posterity, effectively logging the current state of the product, as it was when the user purchased it?

Pros:

  • The product (as the user saw it when it was purchased) is held for posterity and never changed. If the product data changes over time, it won't change the original order information.

Cons:

  • A lot of added complexity:
    • Several more tables required in the database.
    • Similar schema to keep track of.
  • More disk space used.

Does anyone have a clever solution to this conundrum?

A: 

I would suggest adding a 'version number' to the product data, and keeping old versions. This way, you maintain the product data, don't add more tables, and have the option of culling old products and orders later if you are using up too much space.

sje397
Thanks for the response. This is great in theory but I would have to alter my CMS too much to make it work in reality.
mattalexx
+2  A: 

I would suggest cloning the attributes of the product that are relevant to the order. For example, the unit price. Most of the attributes of the product are not part of the order. Which attributes are relevant to the order depends on how the enterprise does business.

If it's just a few attributes, you can clone them directly into the order detail record (row) and not create another table to hold that data. The added complexity is minimal.

That's my suggestion for transaction processing. If, on the other hand you are building up a data warehouse for long term analysis, then keeping a version on the product dimension table is the right way to go.

Then, you would never do an update to the product dimension. Instead, when a product attribute changes, you would insert a new row into the product dimension to hold the new values. The new row would have the same product key, but a different version number.

Walter Mitty
I would include, price part number and name and the units. YOu should also do the same concerning the customer information, you shipped the order to the address you had at the time and should store both the name and address. You don't want updates to that information changing historical details of an order either.
HLGEM
Thanks for the great response. I am going to do this. Also, I'll store a JSON object in the order record as well that includes all relevant data, just in case.
mattalexx