rake railties:install:migrations respects the order of railties

This PR fixes #8930 and some stuff from #8985