It's important to note that running this reset will drop any existing data you have in the application
- Step 1:
heroku restart - Step 2:
heroku pg:reset DATABASE(no need to change theDATABASE) - Step 3:
heroku run rake db:migrate - Step 4:
heroku run rake db:seed(if you have seed)
One liner
heroku restart; heroku pg:reset DATABASE --confirm APP-NAME; heroku run rake db:migrate
Note 1
Heroku doesn't allow users from using rake db:reset, rake db:drop and rake db:create command. They only allow heroku pg:reset and rake db:migrate commands.
More info: https://devcenter.heroku.com/articles/rake
Note 2
If you have more than 1 remote, append --remote [your_remote_name] like this:
heroku run rake db:migrate --remote dev (dev is example remote here)
What if you want your app to reset itself?
Imagine you have some type of demo that needs to reset itself once a day.
Install the Database Cleaner Gem and make sure you make it available for the production environment.
Create a
lib/tasks/scheduler.rakefile that looks similar to thisCommit and do
git push heroku masterAdd the following ENV variables to your Heroku app to disable the Database Cleaner Safeguards. You can do this by logging into your Heroku account.
Test it by running
heroku run rake reset_demoUse the Heroku Scheduler Add-on to program how often should the rake task be executed.