开发者

Rails3 ActiveRecord migrations on concurrent deploy

How do you ensure your migrations are run only once, when you deploy to multiple machines at the same time ?

What I have to do right now is select one machine to run the migrations when I do have a change of that sort. Ide开发者_如何学JAVAally, deployment is brainless and the process would take care of that for me.

My idea currently is to have the migrator look for schemas to migrate and acquire a lock if it has something to do. If the lock is already acquired, it skips the migration alltogether. Reading the ActiveRecord code it doesn't seem to support such idea so it would need some patching.

What's your idea ?


Are you using Capistrano? You can specify a list of database servers and mark one as Primary. Migrations will only be run on that server:

role :app, 'example.com.com'
role :web, 'example.com'
role :db,  'db01.example.com', :primary => true
role :db,  'db02.example.com'
role :db, 'db03.example.com'

EDIT: the :db role is not intended to be used for a separate database server which is not running Rails application code. This probably isn't your setup.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜