Proposal: Stop storing file ids in two tables
File fields in CiviCRM are strange.
When you upload a file to a custom field, it stores a record in the civicrm_file
table. Then it stores that id in two other tables. Once in the custom value column for that field, as you'd expect, and then it also adds a record in the civicrm_entity_file
table.
https://github.com/civicrm/civicrm-core/blob/5.40/CRM/Core/BAO/CustomValueTable.php#L161-L171
From a data archetecture POV, there's no upside to storing the same value twice in two places, it just creates problems.