gpt4 book ai didi

ruby - Rake 依赖不执行但调用有效

转载 作者:数据小太阳 更新时间:2023-10-29 07:00:51 24 4
gpt4 key购买 nike

我一直在尝试运行 rake db:test:clone_structure,但它总是无法重建数据库。我终于看到了任务本身:

task :clone_structure => [ "db:structure:dump", "db:test:load_structure" ]

当我运行跟踪时,我注意到 db:test:load_structure 没有被执行:

$ rake db:test:clone_structure --trace
** Invoke db:test:clone_structure (first_time)
** Invoke db:structure:dump (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:structure:dump
** Invoke db:test:purge (first_time)
** Invoke environment
** Execute db:test:purge
** Execute db:test:clone_structure

现在,当我将 clone_structure 任务更改为 invoke load_structure...

task :clone_structure => [ "db:structure:dump", "db:test:load_structure" ] do   
db_namespace["test:load_structure"].invoke
end

...突然一切正常!

$ rake db:test:prepare --trace

** Invoke db:test:clone_structure (first_time)
** Invoke db:structure:dump (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:structure:dump
** Invoke db:test:purge (first_time)
** Invoke environment
** Execute db:test:purge
** Execute db:test:clone_structure
** Invoke db:test:load_structure (first_time)
** Invoke db:test:purge
** Execute db:test:load_structure
** Invoke db:structure:load (first_time)
** Invoke environment
** Invoke db:load_config (first_time)
** Execute db:load_config
** Execute db:structure:load

什么可能导致这种行为?我正在使用 Rails 3.2.14 和 Rake 10.1.0。

更新:我将 Rails 从 3.2.11 升级到 3.2.13,但问题仍然存在。

更新了第二个:我将 Rails 升级到 3.2.14 并将 Rake 升级到 10.1.0,但它仍然是一个问题

最佳答案

我会说你快到了。据我所知rake惯例是……

task :clone_structure => [ "db:structure:dump", "db:test:load_structure" ] do   
Rake::Task["clone_structure"].invoke
end

否则,我更喜欢...

task :clone_structure do   
Rake::Task["db:structure:dump"].invoke
Rake::Task["db:test:load_structure"].invoke
end

关于ruby - Rake 依赖不执行但调用有效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15888400/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com