Running Migrations Once During a Multi-Host Kamal Deploy | t27duck

29-May-2026 205
At my day job, we deploy our Rails app in production to three separate web hosts using Kamal. Each container runs bin/docker-entrypoint on startup, which runs bin/rails db:prepare. That worked fine when there was only one host (like staging), but ran into issues with many hosts. All containers start at roughly the same moment, all three try to apply pending migrations, and all three race for the same migration advisory lock. .
Use coupon code:

RUBYONRAILS

to get 30% discount on our bundle!
Prepare for your next tech interview with our comprehensive collection of programming interview guides. Covering JavaScript, Ruby on Rails, React, and Python, these highly-rated books offer thousands of essential questions and answers to boost your interview success. Buy our 'Ultimate Job Interview Preparation eBook Bundle' featuring 2200+ questions across multiple languages. Ultimate Job Interview Preparation eBook Bundle