Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ?

like image 465
zimbatm Avatar asked Nov 04 '22 18:11

zimbatm


1 Answers

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.

like image 86
icecream Avatar answered Nov 15 '22 05:11

icecream