Good question. The answer is that only migrations created after the latest db:schema:load
event will ever be run.
The schema.rb file has a version stamp associated with it:
ActiveRecord::Schema.define(version: 20130928225041) do ...
When you run db:schema:load
, Rails creates a fresh database according to that schema.rb file, and at the same time populates the schema_migrations
table with all the migrations whose version number precede that of the schema.
So as far as I can tell Rails is essentially faking all the migrations up until that point, but doesn't actually run them. (I tested this out by generating an empty migration file, calling db:migrate
locally, but then inserting an error into the migration file before deploying it to our server. On the server, we ran db:schema:load
, and the result was that the bad migration was included in the schema_migrations table as if it had been run, even though it clearly had not.)