db:test:clone,db:test:clone_structure,db:test:load和db:test:prepare之间有什么区别? [英] What's the difference between db:test:clone, db:test:clone_structure, db:test:load, and db:test:prepare?

查看:145
本文介绍了db:test:clone,db:test:clone_structure,db:test:load和db:test:prepare之间有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你必须承认,对于rails和数据库的新手,关于rubyonrails.org的官方解释使得这四个任务听起来完全一样。

You'll have to admit, to a newbie to rails and databases, the official explanation on rubyonrails.org makes all four of these tasks sound exactly the same. Quote:

rake db:test:clone  Recreate the test database from
                    the current environment’s database schema

rake db:test:clone_structure    Recreate the test database from the
                                development structure

rake db:test:load   Recreate the test database from the current schema.rb

rake db:test:prepare    Check for pending migrations and load the test schema

甚至知道结构和模式之间的区别。加载当前环境的模式和加载schema.rb有什么区别?

I don't even know the difference between structure and schema. And what's the difference between loading the current environment's schema and just loading schema.rb?

这些任务有多相似(或不同)?

Just how similar (or different) are these tasks?

推荐答案

很好的问题。如果我陷入困境,所以我进入rails源,并拉起 database.rake 。现在更清楚:

Very good question. Had me stumped so I dove into the rails source and pulled up database.rake. Now it's more clear:

db:test:clone 只是 db :schema:dump db:test:load

task :clone => %w(db:schema:dump db:test:load)

db :test:clone_structure 使用{rails_env} _structure.sql文件:

db:test:clone_structure uses the {rails_env}_structure.sql file:

task :clone_structure => [ 'db:structure:dump', 'db:test:purge' ] do
  # skipped some code, here's what happens for MySQL:
  ActiveRecord::Base.establish_connection(:test)
  # ...
  IO.readlines("#{Rails.root}/db/#{Rails.env}_structure.sql").join.split("\n\n").each do |table|
    ActiveRecord::Base.connection.execute(table)
  end
end


$ b b

db:test:load db:schema:load 相同,测试数据库:

db:test:load is the same as db:schema:load, but invokes it on the test database:

task :load => 'db:test:purge' do
  ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations['test'])
  # ...
  db_namespace['schema:load'].invoke
end

db:test:prepare 提示您是否有任何迁移正在等待,如果没有,则运行 db:test:clone_structure (使用{rails_env} _structure.sql文件) code> db:test:load (使用schema.rb文件),具体取决于模式格式(这有点混乱,可能有人可以扩展它) / p>

db:test:prepare alerts you if any migrations are pending, and if not, either runs db:test:clone_structure (using the {rails_env}_structure.sql file) or db:test:load (using the schema.rb file), depending on the schema format (this is a little confusing to me, maybe someone else can expand on it):

task :prepare => 'db:abort_if_pending_migrations' do
  # ...
  db_namespace[{ :sql  => 'test:clone_structure', :ruby => 'test:load' }[ActiveRecord::Base.schema_format]].invoke
end

希望这个清除!同样,通过 database.rake 文件很容易,并会清除您可能有的任何其他问题。该链接指向的是:test命名空间的开头。

Hope this clears it up! Again, going through the database.rake file is easy and will clear up any other questions you might have. That link goes to the line that is the beginning of the :test namespace.

这篇关于db:test:clone,db:test:clone_structure,db:test:load和db:test:prepare之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆