Skip to content

How to Manage Database in ROR using Rake Commands

Rake Database Commands (rake db:create, rake db:migrate), How to Migrate Database in ROR using Rake Commands

Category
Programming
Covers
Ruby
Versions & support
About Ruby →

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
    

Rahul

Rahul Kumar is the founder and chief editor of TecAdmin.net. A Red Hat Certified Engineer (RHCE), he has worked in IT since 2009, with hands-on experience in Linux system administration, DevOps, web hosting, cloud platforms and automation. He started TecAdmin in 2013 to share practical, step-by-step guides, and leads its editorial work with one aim: making technical learning clear and useful for sysadmins, developers and beginners alike.

Leave a Reply

Your email address will not be published. Required fields are marked *


Back to top