It's idea as some kind of workaround using boolean flag cold_deploy
namespace :deploy do
task :_mark_cold do
set :cold_deploy, true
end
end
before "deploy:cold", "deploy:_mark_cold"
task :createdb_if_cold do
createdb if fetch(:cold_deploy, false)
end
before "deploy:migrate", "createdb_if_cold"
Running deploy:cold triggers deploy:_mark_cold, which sets cold_deploy as true
When deploy:cold later calls deploy:migrate, the before hook runs createdb_if_cold, sees the flag and runs createdb
Calling deploy:migrate directly (or via other tasks) will not set this flag, so createdb will be skipped
In this case you don't need to redefine deploy:cold task
May be you can redefine the task? Solution will be much cleaner:
namespace :deploy do
task :cold do
update
createdb # just add one line instead of hooks workarounds
migrate
start
end
end
create_dbinsidedeploy:coldright beforemigratewould be the most straight-forward solution I can think of.