I've got 3 tables:
- orders
- line_items
- products
They're setup as:
order has many products through line_items
This allows me to store in line_items such things as the product_id, quantity, price at time of purchase, discount, etc...
All is well up to this point.
What I'm looking to achieve:
I now need to have some products that have a user changeable status. Meaning that at some point in the future after an order has been processed, the purchased product status can be changed from one status to another.
The product table has a statusable boolean field that tracks whether said product supports a status.
The question:
Would I just add a status field in line_items? Only a small amount of the products will require a status so it feels like a waste but I'm not sure how else to approach this hurdle. My main concern being that I'll end up with a massive table as the application grows and specific products require extra optional fields.
orderandline_itemrecords should be immutable, in append-only tables, as should the copies of product for the orders. So if you must change something after the fact, I'd put it in separate table likeproduct_statusthat you can insert status rows into at order creation time for products that can have a status. Make that table updateable so you can update the status and only the status later. It should be impossible for users to edit any other part of the order after the fact - they should have to append amendments instead. - Craig RingerINSERTon allordercolumns but only grantUPDATEon thestatecolumn, I guess. Personally I'd use a side-table so I could keepordersappend-only, but that's a design preference. Either way you should make sure no other columns can be changed. - Craig Ringer