问题

rake db:migrate 和 rake db:reset 之间的区别在我的头脑中很清楚.我不明白的是如何 rake db:schema:load 与前两个不同.

只是为了确保我在同一页:

  • rake db:migrate - Runs the migrations which haven't been run yet.
  • rake db:reset - Clears the database (presumably does a rake db:drop + rake db:create + rake db:migrate) and runs migration on a fresh database.

请帮助澄清,如果我的理解错了.



解决方法
  • db:migrate runs (single) migrations that have not run yet.
  • db:create creates the database
  • db:drop deletes the database
  • db:schema:load creates tables and columns within the (existing) database following schema.rb

  • db:setup does db:create, db:schema:load, db:seed

  • db:reset does db:drop, db:setup

通常,在通过新的迁移文件对架构进行更改之后,您将使用db:migrate(这只有在数据库中已有数据时才有意义). db:schema:load在您设置应用程序的新实例时使用.

我希望有所帮助.


UPDATE for rails 3.2.12:

我刚刚检查了源代码,依赖关系现在是这样:

  • db:create creates the database for the current env
  • db:create:all creates the databases for all envs
  • db:drop drops the database for the current env
  • db:drop:all drops the databases for all envs
  • db:migrate runs migrations for the current env that have not run yet
  • db:migrate:up runs one specific migration
  • db:migrate:down rolls back one specific migration
  • db:migrate:status shows current migration status
  • db:rollback rolls back the last migration
  • db:forward advances the current schema version to the next one
  • db:seed (only) runs the db/seed.rb file
  • db:schema:load loads the schema into the current env's database
  • db:schema:dump dumps the current env's schema (and seems to create the db as well)

  • db:setup runs db:schema:load, db:seed

  • db:reset runs db:drop db:setup
  • db:migrate:redo runs (db:migrate:down db:migrate:up) or (db:rollback db:migrate) depending on the specified migration
  • db:migrate:reset runs db:drop db:create db:migrate

有关详情,请查看 https:/ /github.com/rails/rails/blob/v3.2.12/activerecord/lib/active_record/railties/databases.rake (适用于Rails 3.2.x)和https://github.com/rails/rails/blob/v4.0.5/activerecord/lib/active_record/railties/ databases.rake (适用于Rails 4.0.x)




相关问题推荐