You ask the right question, but I do not have the right answer.
This task is one part of my update concept were I still don´t know if I automate it by script or manually adjust the TOC after deployment.
To my current (!!!) knowledge, you need to update the sort_order of com.aras.innovator.cui_default.toc AND sort_order of the individual TOC sections of each ItemType.
So theoretically you only have to merge sort_order of table CommandBarSectionItem, cause this table contains all elements. Maybe just merge the table completely with SQL. You could maybe also use an AML script to update the items to the new target values.
If you have a subscription, ask Aras! You will not be the only person that is interested in this one, so I see a big chance they will provide a generic script for this task. ---> “Awesome idea with the custom TOC but how on earth do you expect us to import/export these data?”