开发者

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:

  1. 001_smomething
  2. 002_blah
  3. 003_bookblah
  4. 20110022211973_smoething

because rails when performs migrations sort files by name.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜