编码购物车:当用户结帐时,我是否应该将每条产品数据复制到“订单产品”中?表保存其状态?
我是否应该将整个产品以及所有相关数据克隆到另一个表中以供后代使用,从而有效地记录产品的当前状态,就像用户购买它时一样?
优点:
- 该产品(如用户购买时所看到的那样)为后代保留并且从未改变。如果产品数据随时间发生变化,则不会改变原始订单信息。
缺点:
- 增加了很多复杂性:
- 数据库中还需要几个表。
- 需要跟踪的类似架构。
- 使用更多磁盘空间。
有没有人有一个聪明的解决方案来解决这个难题?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我建议克隆与订单相关的产品属性。例如,单价。产品的大部分属性都不属于订单的一部分。
哪些属性与订单相关取决于企业如何开展业务。
如果只是一些属性,您可以将它们直接克隆到订单详细信息记录(行)中,而无需创建另一个表来保存该数据。增加的复杂性是最小的。
这是我对交易处理的建议。另一方面,如果您正在构建用于长期分析的数据仓库,那么在产品维度表上保留版本是正确的方法。
那么,您将永远不会对产品维度进行更新。相反,当产品属性发生更改时,您可以在产品维度中插入一个新行来保存新值。新行将具有相同的产品密钥,但版本号不同。
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.
我建议在产品数据中添加“版本号”,并保留旧版本。这样,您就可以维护产品数据,无需添加更多表,并且可以在使用过多空间时选择稍后剔除旧产品和订单。
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.