I'm very curious as to how people run a command like db migrate on their eb apps. If you add it as an .ebextensions I fear that when you have multiple instances for one app, there could be conflicts that occur if multiple servers are trying to run the same migration.

At what point during the deployment process should a db migrate command be run?


You can try the flag: leader_only in an ebextensions configuration file. This flag will make your migration run just once even if you have the app deployed in many instances. For example, save this file into the root directory of your project at the path: /.ebextensions/migration.config

        leader_only: true
        command: "db migrate"

More information: AWS Elastic Beanstalk Official Docs


This sequence works for me, in deploying Rails 5.1.4 to Elastic Beanstalk using PostgreSQL:

  1. Deploy your code to EB. I use the EB console but you might use the CLI instead.
  2. SSH to the EC2 app server
  3. Change to the app directory: cd /var/app/current/
  4. db:reset

BTW, I needed to close pgAdminIII which I was using to examine the RDS database. Since I was connected, this locks the database and prevents the last step.

I also had RAILS_SKIP_MIGRATIONS set to TRUE in the EB console (under Configuration > Software). Presumably if you left this on its default value of FALSE, the deployment would run any migrations required.

So in answer to the original question, you run the rails db:reset (or rails db:migrate) on the app server. You don't (and can't) SSH to the RDS server.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.