我想要仅在舞台不是制作时才需要capistrano /
postgresql.
但是,这个Capfile总是需要capistrano / postgresql,因为fetch(:stage)是空的.
(在Capfile中输入fetch(:stage)||“no stage”打印“no stage”)
require 'capistrano/bundler'
require 'capistrano/npm'
require 'capistrano/rails/assets'
require 'capistrano/rails/migrations'
require 'capistrano/puma'
require 'capistrano/puma/nginx'
require 'capistrano/postgresql' unless fetch(:stage) == "production"
require 'capistrano/secrets_yml'
我应该在config / deploy / staging.rb等中添加require’capistrano / postgresql’.(我不知道它是否有效)?
或者还有其他简洁的方法吗?
编辑
如果我在config / deploy / staging.rb中输入require’capistrano / postgresql’,则会出现以下错误.
WARNING: load:defaults has already been invoked and can no longer be modified.
Check that you haven't loaded a Capistrano plugin in deploy.rb by mistake.
Plugins must be loaded in the Capfile to initialize properly.
(Backtrace restricted to imported tasks)
cap aborted!
can't modify frozen #<Class:#<Rake::Task:0x007fd8bcd22868>>
最佳答案 在Capefile中添加
task :use_postgresql do
require 'capistrano/postgresql'
end
task 'staging' => [:use_postgresql]
这样,capistrano将仅在staging env上使用posgresql