I am setting up a Postgres database that keeps track of items that entities in my system own. Each incoming datum says that Entity Q has N of Item X.
My first instinct is to have a separate table for each entity (multi-tenant). But I have read a number of posts advising against that due to scalability concerns.
What is the most effective way to design a database that stores a many-to-many relationship along with quantities? Thanks.
Additional information:
My information is coming through in JSON format from an API. For example:
{
"data": [
{
"entity": "John",
"item": "apple",
"quantity": "5"
},
{
"entity": "Mary",
"item": "apple",
"quantity": "2"
},
{
"entity": "John",
"item": "orange",
"quantity": "6"
}
]
}
My system must be able to tell each entity what items they have and how many (John has 5 apples and 6 oranges). It does not need to show which entities own any particular item (John and Mary both own apples).
Since each entity is independent I think it might make sense to keep all information in separate tables based on the type of entity. The main concern with this is that many entity tables might contain the same item (such as apples). But I do not think there is a way to combine these duplicates because the quantity of each item is mandatory.
I hope this clarifies some of the uncertainties surrounding my problem. Thank you for your support.