How to use Rails Migrations - Part II

April 26th, 2007 by Yavor Ivanov

 

Migrations
This article is part two of the series about Rails Migrations and it will explain on a deeper level how to use the Ruby on Rails migrations.

 
 

After we spoke about Migrations in our previous article found here we understood the basics needed to use Migrations in Ruby on Rails.

Now to begin with the code and something we did not mention earlier.

You see indexes are something that a good database design MUST contain!
This example shows how to add and remove an indexed field.

 

And now let’s take a look at some examples which might or might not be so obvious to make.

Read the rest of this entry »




You like it? Digg it!

Tags: , , ,


How to use Rails Migrations - Part I

March 19th, 2007 by Yavor Ivanov

 

Migrations
This article is part one of the series about Rails Migrations and it will explain on a basic level how to use the Ruby on Rails migrations.

 
 

1. What are Migrations ?

Migrations in Rails is a way of describing what the database should look like and synchronize it with the respective model.
Migrations are abstract to the database they are used with. This means that if you have used a MySQL database server when developing the application and the production database server is different let’s say Postgresql the database you defined within the migrations will remain intact and will run just fine on the new database server.
Migrations provide a way to make the database development SVN like… I will cover this latter on so just keep in mind this for now.

 

2. Creating and Running Migrations

A migration is a simple Ruby file in the db/migrate directory.
Each migration file has a name starting with three digits and an
underscore. Those digits are the representation of the migrations version (a bit like SVN),
because they define the sequence in which the migrations are applied.

To generate a migration type:

Notice: This will generate a model and a migration to it.

 

Read the rest of this entry »




You like it? Digg it!

Tags: , , , ,