Caveats when using custom fields¶
Imagine you're adding extra information fields to your customer database in Mautic. It's like adding new columns to a spreadsheet where you keep all your customer details. While this is super useful, there are a few things to consider to make sure everything runs smoothly.
Database performance¶
Field Type Selection¶
- Choosing the appropriate field type is critical.
VARCHARfor short text,TEXTfor longer text,INTfor integers,DATETIMEfor dates, etc. Incorrect selection can lead to inefficient storage and slower queries. - Avoid using
TEXTorLONGTEXTfor fields that will be frequently used in filters or segments, as these types are generally slower for comparisons.
Indexing¶
- If a custom field will be used frequently in segments, filters, or reports, consider adding an index to that field in the database. Without an index, queries involving that field will be much slower.
- Be mindful that excessive indexing can also degrade write performance, so index only fields that are truly necessary.
Data Volume¶
- As the number of custom fields and the volume of data increase, database performance can degrade. Regularly optimize your database to maintain responsiveness.
- Consider the overall size of the row of data, as many custom fields that hold large amounts of data, will increase the row size, and decrease performance.
Process table creation in background¶
- If there are a large amount of contacts in Mautic creating the database table for the custom field can take a long time, and lock the table during that process. There is the possibility to delay the table creation to a less busy moment, and execute the real creation of the table at a later moment.
General recommendations¶
- Make sure to clean up not used custom fields.
- The number of custom fields is limited by the maximum column size of a table in the database.
Data Integrity and Consistency¶
Data Validation¶
- Implement data validation rules to ensure that custom fields contain valid and consistent data. Use regular expressions or other validation techniques to enforce data formats.
- For example, for a phone number field, enforce a specific format.
Data Type Mismatches¶
- Ensure that the data type of the custom field in Mautic matches the data type of the corresponding column in the database. Mismatches can lead to data conversion errors.
Null Values¶
- Consider how null values will be handled. Decide whether a custom field should allow null values or require a value.
- Consistently handle null values in segments, filters, and reports.
Character Encoding:¶
- Ensure that the character encoding of the custom field is consistent with the rest of the Mautic database. UTF-8 is generally recommended.
Maintenance¶
Naming Conventions:¶
- Use clear and consistent naming conventions for custom fields to improve maintainability.
Documentation:¶
- Document the purpose and usage of each custom field. This will help with future maintenance and troubleshooting.