Wednesday, December 20, 2006

Migrations in Ruby on Rails

When Ruby on Rails was first released you had to first create a database and all its tables by yourself. If you were using MySQL for instance, you could have created the database and its tables via the command line console or via PHPMyAdmin for instance. You had to do all this outside of Rails then go to Rails in order to start developing your web application.

With the introduction of migrations in Ruby on Rails, now all you have to do is create an empty database without even creating any tables in it. Then you go into Rails and write migrations. Those migrations take care of creating the database tables for you. The really interesting and useful thing about migrations is that you can expand your database by adding more tables or more columns to existing tables in an incremental way. The application would still run smoothly. Most importantly, you can role back to previous states of the database also using migrations. For instance let's say that after you had a database containing a table with 4 columns you made a migration to add a 5th column to that table. You can easily role back to the previous state of the database when it had only 4 columns by using migrations in Ruby on Rails. With complex database structures that have many tables and many columns built in an incremental way, the migration feature of Rails makes it very convenient to go back and forth between different stages of the database without worrying about spoiling it.

No comments: