Actually, the version is much more important than this. The code you provided is actually just a small part of what pred_migrated_upto_version does. The real effect of the version for migration is that all previous migrations (as indicated in the db / migrate directory) are considered to be running. (So ββyes, it does what the function name is.)
This has some interesting consequences, especially when several people make new migrations at the same time.
If you are using the version of schema.rb that the Rails team recommends, you're fine. You are 100% guaranteed to have a conflict (version of the scheme), and the user committing / merging should solve it by combining his changes and setting the version: to the highest of the two. I hope they work correctly.
Some projects prefer to avoid this constant conflict problem by leaving schema.rb out of version control. They can rely solely on migration, or keep a separate version of a versioned schema, which they sometimes update.
The problem occurs if someone creates a time-stamped migration to your version of schema.rb :. If you do db: migrate, you apply their migration, your schema.rb will be updated (but keep the same, higher version) and everything will be fine. But if you should happen with db: schema: load (or db: reset) instead, you will not only miss their migration, but pred_migrated_upto_version will note that their migration has been applied.
The best solution at this stage is likely to require users to re-mark their migrations before they merge.
Ideally, I would prefer that the schema.rb scheme actually contains a list of applicable migration numbers, rather than the "take over" version :. But I doubt that this will happen - the Rails team seems to think that the problem is adequately resolved by checking in the schema.rb file.
Adrian Irving-Beer Oct 28 '10 at 23:13 2010-10-28 23:13
source share