migratebundle: relation inference

The testing is a little on the light side, but has been manually verified against all known bundles
that we need to migrate.

I'd put up a bit of an argument that the filtering bits are self contained enough that they could be their own function. I suspect it's not used anywhere else and it isn't too much code there, so it won't be much of a spirited argument.