ROR migration file names
I have migration files name like.
001_smomething 002_blah 003_bookblah 20110022211973_smoething
What order will thes开发者_StackOverflowe run in?
Behind the scene, the number part at the beginning of the file name is converted to integer. Then the migration files are sorted by version. So it will run in the same sequence as you described:
001_smomething
002_blah
003_bookblah
20110022211973_smoething
You can look at how it works on the source code. Here's the important part:
# Get the number part as version.
version, name = file.scan(/([0-9]+)_([_a-z0-9]*).rb/).first
# Convert version to integer.
version = version.to_i
# Sort the files by version.
migrations = migrations.sort_by { |m| m.version }
They will run in this order:
- 001_smomething
- 002_blah
- 003_bookblah
- 20110022211973_smoething
because rails when performs migrations sort files by name.
精彩评论