If you're using a standard Heroku setup with a postgres database, resetting the database is usually as easy as issuing the command
heroku pg:reset DATABASE. However, if you want to schedule a daily reset with the Heroku Scheduler, you'll have to get a bit more creative since you are unable to call
heroku pg:reset DATABASE from a Heroku instance.
Wait, why not just use
Most people have tried to use a rake
db:reset on a Heroku and seen an error that looks something like:
I don't want to get into the details of how postgres permissions on Heroku work, but the short of it is that this error is raised because
db:reset is actually just a combination of
db:seed in that order. The error is raised when the Heroku instance tries to run
db:create. Unfortunately, these are the parts that actually wipe the database.
So we can't schedule
db:reset, whatever will we do?
Fear not! The indomitable will of the UrbanBound hackers is not to be underestimated! We came up with this janky rake task to accomplish an approximation of the same database wipe effect that we would normally get from
This rake task drops all the tables. When used in combination with
db:seed you can get a reasonable approximation of
db:reset for use in a scheduled reset.