Why does the new Rails db migration file start with datestamp instead of sequence number?

Whenever I use script / generate to create a new scaffold to modify the Rails database, a new migration file is added using datestamp (e.g. 200903140912_create_users.rb) instead of a sequence number (e.g. 004_create_users.rb).

Then I need to manually change the file name so that it matches 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
source share
4 answers

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

+8
source

I'm not sure why they made the decision, but I can tell you how it made my life easier. In a team, it was common for two people to create migrations at about the same time. If the last production migration was 007, then both new ones would be 008. The second person who committed the commit would have a headache in his hands, trying to figure it out, and time stamps make this conflict much less likely.

+4
source

The decision was made because when people worked together on the same project, they often tried to create migration with new changes. This would lead to a problem when two people worked on the same project, making separate changes, but both generated a migration with the same number. The core Rails team decided to change it to a UTC timestamp because it is less likely (but still possible!) That two (or more) developers will create a migration within the same second, and not in the same sequence.

+2
source

It is also worth mentioning that using a UTC timestamp helps with the migration sequence when developers can be in separate time zones.

+2
source

All Articles