I have a CRM application that has all commonly needed profiling fields that a user may need to store customers and related data. But, there are needs for additional related specialty data to be stored for each user's customers.
I have been putting this off as I am still perplexed on the pros/cons of the ways to store user supplemental data in the database.
IDEA 1: Framework of Permanent Application Tables
I have created a framework that requires 5 tables (at least) that would store all supplemental data for all users as a permanent store. It limits the user to adding expanded fields only to tables we designate. It does not allow user to create a new custom table.
User can:
The framework knows the key field name (CustomerID, InventoryItemID) for that table and can join those fields into custom views
(Just to give you an idea why this scares me, here are the tables...)
UserDefinedObject - List of keys field names from our app tables that user may select to store supplemental data fields (stores Name of the parent field that the joining ID belongs to (E.g. CustomerID, InventoryItemID, etc.). This provides the JOIN ON field with app tables.
UserDefinedObject_RefObjectType - Reference table for UserDefinedObject: This is the table name that UserDefinedObject is key for (E.g CustomerID belong to Customer. This provides the JOIN table name.)
UserDefinedObjectAttribute - This is the user's choice field name they want to call the custom data field. (E.g FavoriteColor)
UserDefinedObjectAttribute_RefDataType - Refferece table for UserDefinedObjectAttribute : The data type the user want to store in the field. It is stored as string, but can be converted to user's type when needed.)
UserDefinedObjectAttributeValue - The actual value user want to store and the owner (key value)
E.g. * Custom defined field (Attribute) is FavoriteColor * FavoriteColor Value is Blue and belongs to ObjectType, Customer * Customer row is one with key value of CustomerID, 1212121.
Finally, value is stored as a string but can be converted to it the user-defined type on-read using the UserDefinedObjectAttribute_RefDataType.
PROS: Limited tables. Easy joins.
CONS: User can only add fields to predefined tables. That may be sufficient, but ?
IDEA 2 (I am leaning this way):
Allow the user (through a UI) to specified fields/types, table name that are parsed into an SQL script to create personal semi-permanent tables for each user's needs.
Additionally, and optionally, user could select the key value from app table that their newly created table should JOIN on. These tables would be "extensions" of an existing application table making joins pretty easy.
Unlike the framework this would allow user to select common tables like the framework above but would allow the creation of non-relational tables for what ever they need.
The user's tables would be deleted if the user no longer used the application.
I would appreciate some direction from real world experience.