Skip to content

Run a Rails script in the Heroku console

Joel Meador edited this page Jun 8, 2026 · 1 revision

How can I run a script in the Heroku console to make direct changes to the database?

  1. backup the database
heroku pg:backups:capture --app application-name
  1. run bash in the Heroku console
heroku run bash --app application-name
  1. run ruby script
bundle exec rails runner script/delete_duplicate_contacts.rb

quit

~$ exit

If that fails or a transaction rollback occurs, you can drop scripts directly into the console:

bundle exec rails c
irb(main):001:0> paste script here
irb(main):002:1* each line break will be on a new console line

Home

TODO: can we recreate the tag system here roughly with sections about certain subjects?

Clone this wiki locally