I am currently designing a contact management database for a customer engagement platform using PostgreSQL. The goal is to store all contacts, which can be created via incoming leads or by syncing contacts from a CRM. Each contact can have multiple phone numbers and multiple emails, and one phone/email can be linked to multiple contacts (parent-child relationship).
Here’s the schema I’m considering:
contact: id, name, …
phones: id, number, …
emails: id, address, …
contact_phones: contact_id, phone_id, …
contact_emails: contact_id, email_id, …
Example Cases:
A contact created via the platform should be uniquely identified by a combination of phone and email.
Searching for existing contacts involves looking up both phone and email tables along with contact_phones and contact_emails, which can be inefficient.
Current Challenge:
To create or find a contact, I need to search through contact_phones and contact_emails tables in addition to the phones and emails tables. This seems inefficient and cumbersome.
DB structure
Is there a better way to structure this schema to avoid these multiple lookups while ensuring data integrity and allowing for efficient searches and inserts?
Any advice on optimizing this schema or alternative approaches would be greatly appreciated.
Param Saluja is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.