Let’s say we are having 10 migration files in our application. Our DB is already set as per our migrations. Now let’s say we got a requirement to add a new column to an existing table. Literally we need to update our migration file and synchronize the same with database.
We are having following migration file in project/db/migrate/20130830131215_create_tips.rb
class CreateTips < ActiveRecord::Migration
create_table :tips do |t|
We got requirement to add a new field “Tag of String type” to our application ( add Tag to our table tips).
We can update the same in our existing migration file : (Just update the create_table section)
create table :tips do |t|
t.string :tag # Here goes our new column
Now we need to make our Synchronized with this change in Migration. So let’s run migration file specific command.
rake db:migrate:up VERSION=20130830131215
Above command will run a specific migration file and update our DB.
Points to keep in Mind :
1. DON’T EVER give any spaces between this VERSION, = & timestamp.
2. If you wish to remove table / go for the down case, then change it to db:migrate:down
3. This version is the timestamp at which this migration file was created
(this long timestamp is attached to our migration file to make it unqiue which will avoid file conflicting )