Little on ruby On rails Migration
Migrations: If you want to make any changes in the database, then migration come into picture.
How to create migration:
>>rails generate migration migration_name
It'll generate a file with file name as per conventions: 20120219053515_Migration_name.rb
Find this file under /db folder
Here you'll find rails has generated two methods for you:
def up
//write changes to be made
end
def down
// write changes to revert back above mentioned changes
end
Write any changes you want to make in database under this methods
How to run migration:
rake db:migrate:METHOD VERSION=TIMESTAMP
eg
>> rake db:migrate:up VERSION=20120219053515
How to run all migrations files under /db folder
>>rake db:migrate
More on this here:
http://guides.rubyonrails.org/migrations.html
Migrations: If you want to make any changes in the database, then migration come into picture.
How to create migration:
>>rails generate migration migration_name
It'll generate a file with file name as per conventions: 20120219053515_Migration_name.rb
Find this file under /db folder
Here you'll find rails has generated two methods for you:
def up
//write changes to be made
end
def down
// write changes to revert back above mentioned changes
end
Write any changes you want to make in database under this methods
How to run migration:
rake db:migrate:METHOD VERSION=TIMESTAMP
eg
>> rake db:migrate:up VERSION=20120219053515
How to run all migrations files under /db folder
>>rake db:migrate
http://guides.rubyonrails.org/migrations.html
No comments:
Post a Comment