Mysql – Database Design – Custom Attributes / Columns

database-designeavMySQL

So I'm trying to figure out the best way to go about handling this database design wise. This is a rough idea of how I THINK it should go, but not really sure.

If I have orders that have their own necessary attributes that a user can create for all of their orders to have, and if the order can be comprised of items, and those items also can have their own custom attributes, and not necessarily the same attributes as the order, what makes the most sense?


Orders  
====== 
id  
client_id 

Items  
=====
id  
user_id  
name 

Attributes  
========== 
id  
user_id  
is_order_attr  
is_item_attr  
name  
type 

Orders_Attributes
=================
id
order_id
attribute_id
value

Items_Attributes
================
id
item_id
attribute_id
value

A) Have an Attributes table for Orders and an Attributes table for Items, subsequently storing the values in another table, say Orders_Attributes_Values and Items_Attributes_Values?

B) Storing everything in a JSON Data Type column in some type of Orders_Configs table and then storing the values in additional tables with the JSON Data Type?

or

C) Something completely different?

Best Answer

A small JSON blob on Items to cover the wide range of descriptors of a item might be prudent. The rest of Orders / Clients tables should be fairly structured and not need any attributes.

Considering attribute tables as a primary design will get you into a mess when queries 3. EAV Tables — Entity-Attribute-Value Tables. A sharded Attribute table between a variety of other tables will make this even worse.