douxin8383 2019-04-03 05:47
浏览 90

电子商务数据库设计,保存产品信息而不影响历史数据

What would be the best, if not, the practical way to design an e-commerce database wherein the product information of the product purchased by a customer should not update when the product information was updated?

To give a better understanding, here's a scenario:

  1. Merchant created "Product A" where it is priced at $50.
  2. Customer saw Product A and purchased it.
  3. Customer visited the transaction history and viewed his recent purchase: Product A priced at $50
  4. Month's after, Merchant updated the price of Product A to $80.
  5. Customer viewed again his transaction history. His transaction with Product A should retain at $50 and not the updated price of $80 because it was the price he paid that time.

One solution I am looking into is to save the whole product information in a table as a PHP serialized data in "purchases.product_information".

Is it even a good idea to store PHP serialized data in a column? How's performance if a user wanted to search for a text in the product information like price, item name, etc.?

Any other workaround for this?

Thank you

  • 写回答

1条回答 默认 最新

  • donglu9896 2019-04-03 07:41
    关注

    It is a case of slowly changing dimensions (https://en.wikipedia.org/wiki/Slowly_changing_dimension)

    A simple solution will be to have a separate table purchase_items and have all the columns that may change over time against each item (Example:price, discount etc) and purchase and purchase_items table will have one_to_many relationship

    Although, there are more complex situations where the price of the product changes on the fly based on the time at which an order is made in a day etc. In these cases, the price may not be stored against the product itself

    This answer is addresses exactly the issue and you might find this helpful https://dba.stackexchange.com/questions/57992/ecommerce-orders-table-save-prices-or-use-an-audit-history-table

    评论

报告相同问题?

悬赏问题

  • ¥50 potsgresql15备份问题
  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上