As far as I can tell, the capistrano :db
role is used only to run migrations.
(Thus, in most cases it probably shouldn't actually be the server that runs your database. Why would you have a ruby/rails stack there (or allow ssh logins there)? it's just whatever server you want to actually execute the rails migrations).
And only the server identified as db role with :primary => true
is used to run migrations.
So any other servers identified as 'db' role but without :primary => true
... are used for nothing at all? So why does the default deploy.rb created by capify .
encourage you to list them? What would you even list here?
Anything I'm missing?
Obviously, the name of role :db
is misleading. As you pointed out, Capistrano defines it (with :primary => true
) as a host that we execute rake db:migrate
on, but database servers are not always running on such hosts. We can alter the schema of remote database server through a Rails app. The correct role name for this kind of host is not :db
.
Inferring from the comments on lib/capistrano/configuration/roles.rb, the original meaning of the role :db
is a host on which database servers are running. We are expected to login to the :db
hosts and do some tasks.
The designers of Capistrano should have defined :migration
role or something else for the deploy:migrate
task. But the association between the :db
role with this task was defined six years ago with 9a6d2fb and has not been changed since then.
Generally speaking, the users of Capistrano can define roles and associate them with tasks freely. The deploy:migrate
task is provided just as a recipe for Rails developers. Unfortunately, this recipe includes a misconception about how we do the database migration and is used widely for a long time.
You may have a setup that includes a master database server and multiple slave servers. In some cases, you could have an capistrano task that needs to be run on all database servers. In others, you may want to run a task (for instance, a migration) only on the master server and allow the changes to propagate to the slave instances.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With