- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
您必须承认,对于 Rails 和数据库的新手来说,rubyonrails.org 上的官方解释使所有这四个任务听起来完全一样。引用:
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 有什么区别?
这些任务有多相似(或不同)?
最佳答案
很好的问题。让我难住了,所以我潜入了 Rails 源并拉起 database.rake
.现在更清楚了:
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
文件:
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
db:test:load
与 db:schema:load
相同,但在测试数据库上调用它:
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
文件)或 db:test:load
(使用 schema.rb
文件),具体取决于模式格式(这是一个我有点困惑,也许其他人可以对此进行扩展):
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
命名空间开头的行。
关于ruby-on-rails - db :test:clone, db :test:clone_structure, db :test:load, 和 db :test:prepare? 有什么区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7693365/
您必须承认,对于 Rails 和数据库的新手来说,rubyonrails.org 上的官方解释使所有这四个任务听起来完全一样。引用: rake db:test:clone Recreate the
我是一名优秀的程序员,十分优秀!