简体   繁体   中英

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. Ideally, 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM