I'm having difficulty designing a schema for my postgresql database that relates to the items a store can create.
There are three possible categories: (1) Clothing (2) Footwear (3) Other.
The problem is that each clothing item can vary in the colours available, the sizes available, and number of images. Meaning a user can click to create an item, and then continue adding more available colours with their respect size and quantity. Something similar to:
[ITEM TITLE input]
[COLOR input]
- [SIZE input] - [QUANTITY input]
[IMAGES input]
[+ to add more colors]
If the only variable value was color, I could just “normalize” the model, and create an available colours
table with a relationship back to the item. I'm not sure how to handle the additional variable of available sizes. What's more, the Other
category wouldn't have colours or sizes available to it, only quantity.
Does anyone know if there's a solution to this type of problem, or a design pattern that I could read up on that might apply? I'm trying to wrap my head around how I could design this model and I'm coming up blank. Ideally I'd be working with a nosql database in this case but that's not possible.
color
andsize
columns in theitem
table, which are left NULL for items in the "Other" category? This seems simple enough to avoid going with an EAV solution. (Entity, Attribute, Value table: stores unique ID, category name, and option name (for example,123, 'Color', 'Red'
;124, 'Size', 'XL'
)..master_item
table, which holds all the information that applies to all colors and sizes of a given base item, and theitem
table having the color, size, and quantity. Withcolor
andsize
left NULL for "Other" type items (so amaster-item
of type "Other" should only have one row initem
). At some point, anything that must be ordered or counted should logically have a unique ID by which it's ordered, and a quantity representing the number on hand..