If you really talk about AH and not ePO servers then I think you just need to disable the AH under ePO, upgrade AH to 5.1 and then enable it again so the assignment rules will be still there and no ned to re-assign them
Can we migrate an AH from ePO 4.6 server to a new ePO 5.1 server?
For a migration, you must verify the sistem operation of ePO. For exemple, for ePO 5.1 you must have a SO 64 bit (like 2k8 R2 or 2012). In the next step, you must verifiy the DB.
For last thing, you should run the compatibility tool present in the distributions of ePO.
Agent Handlers are not migrated like you would do with ePO. You need to remove the AH from the server and then install the new version.
That's why it's important to disable the AH in ePO prior to uninstall/install, otherwise it will disappear from the ePO's Agent Handler list and so the assignements will be lost