Migrating Database
TAGS:
ruby rails migration database
1- Creating Migrating File Using Scaffold.
Migrating Database: After any changes on database in rails application using ruby code, you must assure that changes have been applied to the database it self, this is called Migration.
Or converting ruby code to build database tables, columns, properties, changes, and so on.
This can be done using rake or “ruby make” command.
rake db:migrateThis migration will do changes to database according to a file with a name of date-time stamps in /db/migrate folder as:
20150522235057_create_books.rbThis means that this file has been generated in 22/5/2015 (year month day) at 11:50:57pm (hour minute seconds).
Ex: If you create rails application via scaffold, you must make migration to create the database tables as :
rails generate scaffold book title brief:textThis will generate a new file in db/migrate/(date-time stamp)_create_books.rb.
Then, Apply changes to database using:
rake db:migrateNote that you can undo this migration using:
rake db:rollbackAs shown in this tutorial video :