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