Capistrano ã® db ãã¼ã«
æè¿ Capistrano3 ã触ã£ã¦ãã¦ããã£ãã®ã§å¿ããªãããã«ã¡ã¢ã
æ¨æ¥èº«ã«æã¿ã¦åãã£ããã§ãããCapistrano ã§ã® ãrole: :dbãã£ã¦ãRDBMS ãåä½ãã¦ãããµã¼ããã§ã¯ãªããããã¾ã§ãrake db:migrate ãå®è¡ãããµã¼ããã«å¯¾ãã¦æå®ããããã®ãã¼ã«ã ã£ããã§ããã
Capistrano3 ã使ã£ã¦ãã¦ãæå以ä¸ã®ãã㪠server æå®ãæ¸ãã¦ãã¾ããã
server '192.0.2.1', user: 'vagrant', roles: %w{web app} server '192.0.2.2', user: 'vagrant', roles: %w{web app} server '192.0.2.3', user: 'vagrant', roles: :db, no_release: true # DBãµã¼ããæå®
ãrole: :dbã㯠DBãµã¼ãç¨ã®ãã¼ã«ãã¨æãè¾¼ãã§ããã®ã§ããRDBMS ãåä½ãã¦ãããµã¼ãããæå®ã
ã¾ããDBãµã¼ãã«ã¯ã¢ããªã¯æ®éç½®ããªãã ããã¨ããäºã§ãno_release: trueããæå®ãã¦ãã¾ãã
ãã®ç¶æ
ã§å®è¡ãã¦ã¿ãã¨ä½åº¦ãã£ã¦ãã¨ã©ã¼ãçºçãã¦ãã¾ããããã¤ãæ£å¸¸ã«è¡ãã¾ããã
試ãã« roles: :db ã® server å®ç¾©ãã³ã¡ã³ãã¢ã¦ããã¦ã¿ãã¨ãããã¤ã¯æ£å¸¸ã«çµäºãã¾ããããå½ç¶ã§ãã DB ã¸ã®ãã¤ã°ã¬ã¼ã·ã§ã³ã¯å®è¡ããã¦ãã¾ããã§ããã
ãããã試è¡é¯èª¤ãã¦ã¿ã¦ããªããªãåããå°ã£ã¦ããã®ã§ããã調ã¹ã¦ã¿ã㨠Stack Overflow ã«ä»¥ä¸ã®æ稿ãçºè¦ãã¾ããã
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.
http://stackoverflow.com/questions/9781767/capistrano-db-role-whats-it-for/13637551#13637551
ã½ã¼ã¹ã³ã¼ããèªãã§ã¿ãã¨ã確ãã« migrate ã¿ã¹ã¯ã¯ role: :db ã®ãµã¼ãä¸ã§ release_path ã«ç§»åã㦠rake db:migrate ãå®è¡ããããã«å®è£ ããã¦ããããã§ãã
ã§ããã°æ¬å½ã® DB ãµã¼ãã® IPã¢ãã¬ã¹ã¯ database.yml ã«ã ãæ¸ãã¦ããã° OKãã¨ããäºã«ãªãã¾ããã
ã¨ããããã§ã以ä¸ã®ããã«ä¿®æ£ããã¨ãããä»åº¦ã¯ãã£ããåä½ãã¾ããã
server '192.0.2.1', user: 'vagrant', roles: %w{web app db} server '192.0.2.2', user: 'vagrant', roles: %w{web app}
åãã£ã¦ãã¾ãã°ãããããã ããªãã¨ããæãã ã£ããã§ãããããããæ¤ç´¢ãã¦ã¿ã¦ããDBãµã¼ãã«ã¯ role: :db ãæå®ãã¾ããã¨ãããããªäºãæ¸ãã¦ããè¨äºãçµæ§ãã£ãããã¦ããªããªãæ°ä»ãäºãåºæ¥ã¾ããã§ããã
ã¨ã©ã¼ã¡ãã»ã¼ã¸ã DB ãµã¼ãä¸ã§ current ã«ç§»åãããã¨ãã¦ãã£ã¬ã¯ããªãç¡ãï¼ã¿ãããªæãã ã£ãã®ã§ãä½è¨ã«åããè¾ãã£ãã§ããã
è¨ã訳ã§ããã©ã
Stack Overflow ã®æ稿ã§ã¯è³ªåè
ã capify . ã¨ãæ¸ãã¦ããã®ã§ãã©ãã Capistrano2 ã®é ããããããæåã ã£ãããã§ãã
ããã£ãè¨æ¶ãç¡ãã£ãã®ã§ã念ã®çºéå»ã«æ¸ãã deploy.rb ã確ããã¦ã¿ãã¨ããã¼ã«ã«ã« HAProxy ãç«ã¦ã¦ 127.0.0.1 㧠DBãµã¼ãã¸ã¢ã¯ã»ã¹ããããã«ãã¦ããã確ãã« role: :db ã«ã¢ããªãç½®ãã¦ããªããµã¼ãã® IPã¢ãã¬ã¹ãæå®ãã¦ãããã®ã¯ããã¾ããã§ããã
ã ããæ°ä»ããªãã£ãã®ãã»ã»ã»ã
ããã«ãã¦ãæ¤ç´¢ãã¦ããã¾ãå°ã£ã¦ã人ãããªãã£ããã§ããããã®è¾ºãã£ã¦å¸¸èã ã£ãããããã§ããããï¼
æåãããã㨠role åã db ã¨ããã®ãæ··ä¹±ã®å
ã®ãããªæ°ããã¦ãªããªããã§ããã»ã»ã»ã
ååã«æç´ã£ãããã§ãåã¯ããã£ãäºãªãã§ãããã¨ã¯ã£ããè¨ããã¦ãªããã·ã§ãã¯ã§ããã
ç²¾é²ãããã¨æãã¾ãã
åè
Capistranoã§migration | kaeruspoon - ããããã¤ãã
http://www.kaeruspoon.net/articles/350