vishless
vishless

Reputation: 898

Difference between rails db:migrate:reset and rails db:reset

This is what I got when I ran both commands

rails db:migrate:reset

$ rails db:migrate:reset
Dropped database 'db/development.sqlite3'
Dropped database 'db/test.sqlite3'
Created database 'db/development.sqlite3'
Created database 'db/test.sqlite3'
== 20190824101540 CreateUsers: migrating ======================================
-- create_table(:users)
   -> 0.0005s
== 20190824101540 CreateUsers: migrated (0.0005s) =============================

== 20190825083402 AddIndexToUsersEmail: migrating =============================
-- add_index(:users, :email, {:unique=>true})
   -> 0.0005s
== 20190825083402 AddIndexToUsersEmail: migrated (0.0006s) ====================

== 20190825085927 AddPasswordDigestToUsers: migrating =========================
-- add_column(:users, :password_digest, :string)
   -> 0.0006s
== 20190825085927 AddPasswordDigestToUsers: migrated (0.0006s) ================

rails db:reset

$ rails db:reset
Dropped database 'db/development.sqlite3'
Dropped database 'db/test.sqlite3'
Created database 'db/development.sqlite3'
Created database 'db/test.sqlite3'
-- create_table("users", {:force=>:cascade})
   -> 0.2180s
-- create_table("users", {:force=>:cascade})
   -> 0.1696s

Looks like rake db:migrate:reset and rake db:reset does the same things except the fact that rake db:migrate:reset also displays the migration log.

Is there any difference between the two? Or is one just an alias for the other?

Upvotes: 1

Views: 1906

Answers (3)

Jayaprakash
Jayaprakash

Reputation: 1403

db:migrate:reset runs db:drop db:create db:migrate

rails db:reset runs db:drop db:setup

References:

Difference between rake db:migrate db:reset and db:schema:load https://jacopretorius.net/2014/02/all-rails-db-rake-tasks-and-what-they-do.html

Upvotes: 2

code_aks
code_aks

Reputation: 2074

db:reset It will drop your database (same as undoing all migrations) and reset to the last schema. In short If you wanna drop the database, reload the schema from schema.rb, and reseed the database use this command.

db:migrate:reset: A more correct approach will be using rake db:migrate:reset. That will drop the database, create it again and run all the migrations, instead of resetting to the latest schema.

For further information please have a look at :-https://github.com/rails/rails/blob/v3.2.12/activerecord/lib/active_record/railties/databases.rake (for Rails 3.2.x) and
https://github.com/rails/rails/blob/v4.0.5/activerecord/lib/active_record/railties/databases.rake (for Rails 4.0.x)

Upvotes: 2

Tejas
Tejas

Reputation: 186

db:migrate:reset Resets your database using your migrations for the current environment.

db:reset Drops and recreates the database from db/schema.rb for the current environment and loads the seeds.

For further information please have a look at https://github.com/rails/rails/blob/6-0-stable/activerecord/lib/active_record/railties/databases.rake

Upvotes: 1

Related Questions