Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rails db:migrate vs rake db:migrate

I'm new to rails. I noticed when generating data migration in rails 5, some people use rails db:migrate over rake db:migrate. Can someone explain the difference between the rails vs rake command in database migration? Does it mean rake command is obsolete in rails 5?

many thanks

like image 817
York Wang Avatar asked Jul 15 '16 19:07

York Wang


People also ask

What is the difference between Rails db Migrate and rake db migrate?

What happens internally is that when rails db:migrate command is executed, Rails checks if db:migrate is something that rails natively supports or not. In this case db:migrate is not natively supported by rails, so Rails delegates the execution to Rake via Rake Proxy.

What is Rails db Migrate?

A Rails migration is a tool for changing an application's database schema. Instead of managing SQL scripts, you define database changes in a domain-specific language (DSL). The code is database-independent, so you can easily move your app to a new platform.

What is rake file in Rails?

In Rails, Rake is used for common administration tasks, especially sophisticated ones that build off of each other. You can get a list of Rake tasks available to you, which will often depend on your current directory, by typing rake --tasks. Each task has a description, and should help you find the thing you need.

What does rake db setup do?

rake db:migrate makes changes to the existing schema. Its like creating versions of schema. db:migrate will look in db/migrate/ for any ruby files and execute the migrations that aren't run yet starting with the oldest.


Video Answer


1 Answers

Rails core team decided to have consistency by enabling rails command to support everything that rake does.

For example in Rails 5 commands like db:migrate, db:setup, db:test etc which are part of rake command in Rails 4 are now being supported by rails command. However you can still choose to use rake to run those commands similar to how they were run in Rails 4. This is because Rails community has introduced Rake Proxy instead of completely moving the command options from rake to rails.

What happens internally is that when rails db:migrate command is executed, Rails checks if db:migrate is something that rails natively supports or not. In this case db:migrate is not natively supported by rails, so Rails delegates the execution to Rake via Rake Proxy.

If you want to see all the commands that is supported by rails in Rails 5 then you can get a long list of options by executing rails --help.

like image 67
Vishal Avatar answered Sep 28 '22 08:09

Vishal