I'm currently working on a web business application that has many entities (people,organizations) with lots of contact information ie. multiple postal addresses, email addresses, phone numbers etc.
At the moment the database schema is such that persons table has postal address columns, phone number columns as does organizations table. This is not a good way to handle this.
I've read the c2 Wiki on this and there's some good discussion regarding Contact and address models (http://c2.com/cgi-bin/wiki?ContactAndAddressModels) and wheter or not physical addresses are archaic (http://c2.com/cgi-bin/wiki?ArePhysicalPostalAddressesArchaic). These two discussions really opened my eyes on the scope of this problem.
I'm thinking about separating contact information fields to separate table(s). But what's the best way to do this. At the moment the application mainly handles Finnish addresses but it's on the horizon that it needs also to handle international addresses.
I could define an "addresses" -table, a "phone numbers" -table, an "email addresses" -table and so on and these would be linked to people and organizations. But this just feels too much like the previous solution: it's inevitable that the predefined database schema isn't sufficient.
What I'm proposing is to create a contact information schema/program logic that is dynamic:
- There are no predefined contact information fields/field sets
- Users can define new contact information types and required fields at any time like
- Finnish postal address
- Swedish postal address
- ... postal address
- Phone number
- Email address
- ICQ-number
Is this feasible? Has anyone done anything like this?
There could be a table that defines contact information types:
contact information types
- Id: Identifier
- Name: "Finnish postal address"
- Description: "Use this contact information type for finnish postal addresses"
Then there could be a table that defines what fields are used per contact information type:
contact information type fields
- Id: Identifier
- Contact_information_type_id: References the previous table
- Field title: "Address line 1"
- Field description: "Use this line for postal addresses' first line"
- Field type: String/Integer/etc.
- Field format: Regular expression for validating field data
- Field order: In which order should this field appear when displaying/using this contact information type
Then we'd have a "contact information table" that just is used to map contact information fields together:
contact information
- Id: Identifier
- Contact_information_type_id: References the contact information type table
Then we'd have a "contact information of person" -table mapping different contact information to persons:
contact information of person
- Id: Identifier
- Contact_information_id: References the contact information table
- Person id: References the person
Then we'd need tables per contact information field type like:
contact information integer fields
and so on for strings etc...
Finally when displaying different contact information of a given person this would happen through person's contact information -table whis looks up what fields are used to form this contact information from contact information type fields -table through contact information -table. After determining what fields are used all the necessary tables would be joined together.
I'm having doubts about the feasibility of in SQL. Any thoughts?
In Java I probably could program some logic to determine what tables are neede to form a contact information entity and then i could use some sort of dynamic beans to represent this data in Java. But that's a bit foggy to me too. Anyt thoughts on this too?