简体   繁体   中英

Database Table structure for CRM application

I am working on a small CRM application based on PHP & MySQL. I am following SaaS architecture. Single Code base and every client have their own database.

  • Keep in mind all contact informations should be imported from CSV.

  • My objective is to allow clients to modify contact table structure. I mean each client can define their own table structure.

Example:

  • A client from photography industry, like to collect customer information as follows:

    Name, Address, City, State, Country, Phone, email, whatsapp

  • Whereas another client from SEO industry, ike to collect customer information as follows:

    First Name, Last Name, Address, City, State, Country, Phone, email, website, skype

What would be the best table structure to match all needs.

I hope I have explained my question clearly, If you face any difficulty understanding my question, please comment, I will correct it.

Allowing the client to modify table structure presents several challenges, not in the least is: What happens if they want to change their structure to add or subtract new fields? How do you add validation code? As well as more complex security concerns...

An Object-Oriented Database would be a good way to implement this, but you have indicated that MySQL is a requirement, so one way to approach this from an architectural perspective is to have a table of customer specific schema where the customer key maps to specific table schema that can be modified dynamically.

Forms metadata and associated table operations can be stored in the database to dynamically generate the input fields and such required as they are needed. Since the table schema should be re-generated infrequently, this is not much additional overhead.

Using XML to represent the schema, I once implemented something like this by implementing functions that generated SQL code and HTML forms based on stored schema. When fields were added or changed, the application generated new XML and associated SQL for modifying the table via XSLT.

EG

Schema       DBtoSchema( Database )
DataBase     SchematoDB( XML_Schema )
Schema       DBTabletoSchema( Table )
DBTable      SchemaToDBTable( XML_Schema )
SuccessCode  SchemaAddField( XML_Schema, FieldName, FieldType, FieldValidation)
SuccessCode  SchemaDeleteField( XML_Schema, FieldName)
SuccessCode  NewTable( Schema )
SQLCode      GenerateInsertSQL( Schema )
SQLCode      GenerateDeleteSQL( Schema )
HTMLCode     GenerateForm( Schema, xsltCode)
 ... and so on .....

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM