The purpose of this sub task is to add upgrade code to fix the numerous database discrepancies between a fresh install and an upgraded site.
Please see MDL-25677 for a full list of things to fix.
Fix old upgrade code that is causing discrepancies between fresh installs and upgraded sites.
Created PULL-70 with a patch for this issue.
Linking to sister MDL-25789
as commented in PULL-70, I'm reopening this because I think it needs some more work (missing bits/sync with MDL-25789).
Thanks for the feedback, I've fixed the noted issues + several more.