With a chef, how do I run Rails migration only once?

I am running a Rails application with three web servers and one database server (AWS RDS server). I deploy with chef Solo. I am currently setting "migrate true" in my rails_app recipe, and "rake db: migrate" runs once on each web server.

This is usually not a problem when migrations are short. (The first is successfully completed, and the second and third are skipped because the schema_migrations table lists the latest version of the scheme.) But when the migration takes a lot of time, the second and third web servers try to migrate before the first is completed, They fail, and the chef comes out unsuccessfully. Please note that the migration was successful (at least when I tried it), but the full deployment of the new version fails. (If I run it again, everything will be successful since the migration is already running.)

My question is: what is the best / canonical way to ensure that migration is done only once?

+5
source share
3 answers

, , db/migrate.rb. , migrate true. git,

"git diff HEAD @{1} HEAD db/migrate"

- , migrate true.

0

, , node, .

rails_app migrate :

migrate node['rails']['migrate']

node json node ;

"rails" : { "migrate" : true }

"rails" : { "migrate" : false }

, / .

0

- db: migrate .

- dbserver, db: .

0

All Articles