The handle_ado_upgrade function has become too big and it's hard to read/understand. It should be reworked and simplified where possible