rake railties:install:migrations respects the order of railties

This PR fixes #8930 and some stuff from #8985
Merge pull request #15269 from arunagw/aa-fixes-8930

rake railties:install:migrations respects the order of railties