Corbi-Wan KenobiC
Convex Community12mo ago
2 replies
Corbi-Wan Kenobi

Suggestions on schema best practice?

Bringin my data from postgres, this is one model I've been using and I'm wondering if this would not be better in convex as arrays. I'm coming from an SQL background with the usually weight on normalization.

I have a people table, a phone_number_types table, and a person_numbers table linking the two with fireign keys (what is convex-speak for primary and foreign keys? same thing? Convex doesn't specificy foreign keys in their tables, right?). This allows for a given person to have one or more phone numbers attached to them with different types. Some people will only have one number, others will have several. I didn't want my people table to have fields for 5 possible types of numbers most of which would be empty for most people. I also have the same structure for email addresses and physical addresses.

I'm wondering, from a convex perspective, is it better to store these kinds of things in array fields in the people table? It would mean far fewer relational joins, but I read in one of the docs it is better to not have too deeply nested of array fields. The array might look like {phone_numbers: {home: xxxxxxxxxx},{mobile: yyyyyyyyyy}}

I actually had this a year or so ago when I was playing with MongoDB. Is it a matter of preference in this case since its really only a two level deep array?
Was this page helpful?