Posts and comments have a canonical URL (i.e. the original submission's URL that's linked to via the Fediverse pentagram), so that can be used as a foreign key when comparing.
I think identify claiming would need to have been designed into the original spec with something like a public/private key for account ownership to allow moving of related data in a safe way, or e.g. editing a post from a different instance than originally posted it.