How to Manage Database in ROR using Rake Commands
Abstract: load This command will load the schema into the current environment’s database. $ rake dbmigrate RAILS_ENV=development
Rake provides an efficient way for managing database changes. We can easily migrate database changes to servers using command line utility. In this article you will find some quickly uses of rake commands for database migrations.
- rake db:create
This command will take all database configuration from config/database.yml file and create appropriate database of current environment’s database.
$ rake db:create RAILS_ENV=development
- rake db:migrate
The creates tables in database. It takes all files under db/migrate/ directory and execute one by one from older to newer files.
$ rake db:migrate RAILS_ENV=development
- rake db:drop
This drops the database for the current environment.
$ rake db:drop RAILS_ENV=development
- rake db:migrate:status
This command will show current migration status.
$ rake db:migrate:status RAILS_ENV=development
- rake db:rollback
This command will roll back the last migration done on current environment’s database.
$ rake db:rollback RAILS_ENV=development
- rake db:seed
This schema runs the db/seed.rb file on current environment’s database.
$ rake db:seed RAILS_ENV=development
- rake db:schema:load
This command will load the schema into the current environment’s database.
$ rake db:schema:load RAILS_ENV=development