Take the 2-minute tour ×

I'm running a Rails app with three web servers and one database server (an AWS RDS server). I deploy with Chef Solo. Currently I set 'migrate true' in my rails_app recipe, and "rake db:migrate" gets run once on each web server.

This usually isn't a problem when the migrations are short. (The first one succeeds, and the second and third are skipped because the schema_migrations table lists the latest schema version.) But when the migration takes a long time, the second and third web servers attempt to do a migration before the first one is finished. They fail and chef exits unsuccessfully. Note that the migration has succeeded (at least when I've tried it), but the overall deployment of the new version fails. (If I run it again, everything succeeds as the migration has already been run.)

My question is, what's the best / canonical way to ensure that the migration is only run once?

share|improve this question
You could listen to that podcast: foodfightshow.org/2013/01/application-deployment.html –  StephenKing Apr 23 '13 at 10:10

1 Answer 1

May be you can check if the content of the db/migrate.rb file has changed. If so, then conditionally invoke migrate true. If you are using git, you can check

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

if any change exists, then use migrate true.

share|improve this answer
that wasn't quite the question unfortunately.. –  Michael Reinsch Jan 25 at 7:32

Your Answer


