views:

440

answers:

4

Whenever I use script/generate to generate a new scaffold for a change to my Rails database, the new migration file is prepended by a datestamp (e.g. 200903140912_create_users.rb) instead of a sequence number (e.g. 004_create_users.rb).

I then have to manually change the file name to fit in with the rest of the migration files.

Does anyone know how to fix this?

System: Mac OS X Leopard 10.5.6
Rails: v2.2.2
Ruby: v1.8.6

+4  A: 

This was introduced in Rails 2.1. According to the migrations docs, you can revert it by setting config.active_record.timestamped_migrations to false in config/environment.rb.

James Gregory
Jeff Dallien
So close! Thanks for the correction
James Gregory
+2  A: 

I'm not sure why they made the decision, but I can tell you how it's made my life easier. On a team it was common for two people to create migrations at roughly the same time. If the last production migration was 007 then both of the new ones would be 008. The second person to commit would have a headache on their hands trying to sort it out, and the timestamps make that conflict a lot less likely.

jshen
That _is_ the reason!
Mike Woodhouse
+1  A: 

The decision was made because when people worked together on the same project they would often try to create a migration with their new changes. This would lead to the issue where two people were working on the same project making separate changes but both generating a migration with the same number. The Rails core team decided to change it to a UTC timestamp since it's way less likely (but still possible!) that two (or more) developers would be creating a migration in the same second, rather than the same sequence.

Ryan Bigg
This has always seemed like a problem best fixed with better communication instead of harder-to-read filenames. When you have two people working on migrations at the same time, they should be in constant contact anyway, because the migration *created* first may not be the one you want *run* first.
Sarah Mei
It's not the matter of the migrations running in order, generally two people won't work on the same table at the same time and have tasks dependent of the other. The problem is that when two people create migrations they BOTH have the same sequence number which then makes rake db:migrate fail.
Ryan Bigg
+1  A: 

It is also worth mentioning that using the UTC timestamp helps with sequence that migrations are run when the developers might be in separate time zones.

Paul C