Search code examples
ruby-on-railsrails-migrations

ActiveRecord::Schema.define info :version in schema.rb --> any need to be sequential?


In the rails db creation script schema.rb, there is this line at the top:

ActiveRecord::Schema.define(:version => 20111127090505) do

The docs (http://api.rubyonrails.org/classes/ActiveRecord/Schema.html) say that the info hash param is optional

  • What is :version used for?
  • Is there any need for this number to be increasing on checkins? I.e., checkin later in the day makes the version number go down...
  • If there are migrations with timestamps greater than given, will they be run run simply because they are not in the migration table, yet the class file exists?
  • Are migration files run sequentially?

Solution

  • The version is used to determine what migration was run last. This will only increase over time. The migration you've run here was created (not run) on the 27th November, 2011 at 09:05:05AM in UTC time. This is what the number is: a timestamp.

    The number will increase every time you run a newly created migration, this is so Rails will know which one has run last and which one to run next. The next migration to be run will be the one with the first one with the greater number than this number.

    And yes, migration files are run in the order they are created.