Ensure 'type' is always set for query field data. #12488
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
Cleanup metadata for query fields to ensure 'type' is always set
Before
Some manually defined fields don't have 'type' defined. No test
After
All defined fields have 'type' defined. Test
Technical Details
Historically 'type' was set on core fields but 'data_type' was set on custom fields.
For some time now we have set 'type' on custom fields as well so all the handling one
Export class that was written for them is actually bypassed. However, it seems there are a bunch
of manually defined fields that don't have a 'type' (note that both 'type' and 'title' are
ensured for any fields exposed via the api or DAO fields).
Some of these fields with no 'type' DO have a data_type - but the data_type code would pass right
through the loop that handles it as they use the 'type' constants & the handling
loop uses the custom value strings.
In theory, but not, IMHO in practice, this could result in a shorter varchar being used for fields
In https://issues.civicrm.org/jira/browse/CRM-19222 a field length of 512 was made possible for custom field strings. This would have been broken
for many months since the Custom fields no longer hit that loop by virtue of having a valid type.
I'm actually 99.99% sure I could just remove the deprecated switch statement - since I could not
find a single instance where 'type' is not set AND 'data_type' is valid. It would
give them 'varchar(255)' instead of text.
Comments
Separately, I'm not convinced we do ourself any favours by not setting all the
varchar fields to 512 length - it seems to me they take up no more space unless they need to,
in which case more space is better than a hard-fail
https://dev.mysql.com/doc/refman/8.0/en/char.html