When multiple people are working on a single Rails codebase and they add migrations with new columns (or tables) and run the migrations in different order there is a problem with schema.rb. After this every time migrations are run the columns swap places if the previous version of the schema.rb file has been commited by the other developer who did run the migrations in different order.
Because of this the developers have to discard the lines where columns swap places to keep the source control clean. Could this be fixed by putting the tables and columns on schema.rb in alphabetical order? Or are people relying on the database’s order of the tables and columns?
It seems you could implement it by sticking
.sort_by(&:name) to https://github.com/rails/rails/blob/3f96b6973b82ad17e443dd1d21be05996fb6fbf0/activerecord/lib/active_record/schema_dumper.rb#L134
– Vesa Vänskä