Suppose my company sells many products, eg domains, t-shirts and vans.
In my current data warehouse star schema design, I have a fact table for invoice items with the following (slightly simplified) schema
fact_invoice_item
id | pk
invoice_item_id | id of invoice in OLTP
dim_customer_key | fk to customer dimension
dim_product_key | fk to product dimension
dim_billing_date_key | fk to date dimension
dim_due_date_key | fk to date dimension
invoice_amount | fact
item_amount | fact
dd_invoice_id | degenerate dimension to group together invoice items on the same invoice
I would now like to start recording metadata around these invoice items. For example, if a domain was bought, what was the domain name. If a van was bought, what was the license plate number. If a t-shirt was bought, what was the colour. What is the best way to achieve this while (ideally) adhering to a star / constellation schema?
Current thinking:
Option 1
Have one generic invoice_item_metadata
dimension table with a fk to it from the invoice_item
table. This dimension table could store the item metadata in json form. Or even just store the purchase metadata in the fact table in json form. This would make things a bit tricky as I'd need to then unpack the json to run any analysis on it.
Option 2
Have a fact table for each type of product bought, eg. fact_domain_purchase
and fact_van_purchase
. These fact tables could have their own structure to best suit the product metadata. These seems logical but then I start to think that a domain is more of a SCD as it could have attributes like suspended/active/expired which are liable to change over time. This leads me to think that I could have a fact_domain_purchase
table with a fk to a dim_domain
table, but then the dim_domain
table would grow at the same rate as the fact_domain_purchase
table, which is undesired.
Does anyone have any bright ideas on how to handle this situation? I'm sure I can't be the first person to tackle this problem, I've found it quite tough getting anything useful back from Google though. Thanks in advance for any help