And because Rails encourages iterative development, it would be very easy to imagine the constant schema changes turning into nightmares.
You could choose to try to roll back the changes by retracing your steps, but it's very error prone. If your schema generation scripts were written for a specific database like My SQL and later in the development process you decide to move to Oracle, you'll have to rewrite the SQL in its entirety.
The Migration library takes the burden of having to remember the details of each database vendor's implementation off your shoulders. To get the most out of this article you'll want to have at least a rudimentary understanding of the way Rails works.
You can override the version number by appending VERSION=x after the command.
You can also pass RAILS_ENV="production" to force the migration to run on the production database (or test, dev, etc.).
There's a great reason for this migration: Rails provides a robust framework built on one of the most flexible languages ever conceived.
One of the tricks in the Rails bag is the concept of "Migrations." Migrations provide an excellent example of why developers would want to use the framework, and here's why: Generally speaking, managing changes to a database schema has been one of the most odious tasks for a team of developers.
Jump over to "Ruby on Rails on Oracle: A Simple Tutorial" if you're new to Rails or you just need a refresher on the conventions upon which Rails relies.
Until now, we've been captive to this ball-and-chain of SQL generation scripts (or whatever your "favorite" mechanism for managing database schemas as been). At the most basic level Migrations allow you to define incremental changes to your data model (and data itself! This sort of approach melds seamlessly with Agile and XP methodologies favored by Rails developers the world over.
Even with a single set of database files rolling out your changes is problematic at best.
And if you need to roll the change back, it's likely that the only way to do it is to drop all the tables, restore to a known good version of your schema, and reload the data from a backup.
To revert our change is simple, you need only drop the table you created in the up definition. You'll probably notice that the filename containing our migration has a three digit number appended to it, 001.