I have demo ROR app in Heroku and I would like to reset PG DB everyday via Heroku Scheduler. I have some commands, but I don't know how I can use they in Heroku Scheduler. I just paste this, but it don't work for me.
commands:
heroku restart && heroku pg:reset DATABASE_URL --confirm APP_NAME_ON_HEROKU && heroku run rake db:migrate && heroku run rake db:seed
Could you please tell me, how I should to use this commands?
for me worked it:
rake db:schema:load DISABLE_DATABASE_ENVIRONMENT_CHECK=1 && rake db:seed
UPD:
the commands(heroku run rake db:migrate) that I performed early, working only from the Heroku CLI. For Heroku Scheduler we must use these commands without a keywords heroku run. rake db:reset don't work, disabled on the side Heroku. Also I couldn't use heroku pg:reset DATABASE_URL --confirm APP_NAME_ON_HEROKU.
useful links:
How to reset PG Database on Heroku?
Running Rake Commands
Here is the official documentation link
You can use the following command below.
heroku run rake db:schema:load DISABLE_DATABASE_ENVIRONMENT_CHECK=1 db:seed
Related
I have a ruby on rails app, leveraging Postgres running in heroku. I have a staging environment and a production environment in heroku. I want to run the heroku run rake db:migrate on the production environment however I can find the command to do so, any help would be greatly appreciated
I think you can just set the remote to get it to pick the right environment:
heroku run rake db:migrate --remote production
When I ran heroku run rake db:migrate --remote it gave me three choices (heroku, staging & test) I ran the command: heroku run rake db:migrate --remote heroku and it worked!! (didn't understand that heroku was calling my production environment "heroku" and not production) thanks again for all your help
How can I clear the cache on Heroku?
I've tried heroku run rails c + Rails.cache.clear and receive the following error
Errno::ENOENT: No such file or directory # dir_initialize - /app/tmp/cache/
I also tried heroku run rake tmp:clear (from this post). The task runs but when I go back into the console and run Rails.cache, nothing has changed.
How can I clear the cache?
Did you try this? (This works with Celadon Cedar with the Heroku Toolbelt package at least)
heroku run --app YOUR_APP_NAME rails runner Rails.cache.clear
Update
If the above does not work, try running:
heroku run rake tmp:create
heroku run rake tmp:clear
I did the following steps for deploying app and migrating my database:
git add -A
git commit -m "add changes"
git push heroku master
heroku run rake db:migrate
In console I see next:
Running `rake db:migrate` attached to terminal... up, run.9234
== 20150713191218 CreateMovies: migrating =================
-- create_table(:movies)
-> 0.0379s
== 20150713191218 CreateMovies: migrated (0.0381s) ============
heroku restart
But heroku run rake db:migrate does not work. When I run my app, my database is empty. I don't understand why. I don't see any errors.
And I'm sorry, that I repeat this question. I saw that people already asked about this problem, but no advice helped me.
try heroku run rake db:migrate RAILS_ENV=production
To populate your database automatically with rake task you need to use the command RAILS_ENV=production rake db:seed(this will populate your production database) and have a seed file in place. But I guess that was not really what you were looking for
Now I am trying to reset database on heroku but got stuck.
I know I should do "heroku pg:reset Database URL but I don't know exactly what the databese url is.
I did "heroku config". So I got some strings. And tried
heroku pg:reset postgres://ffsqtmlnxntfvl:ajqGTMGEmT7U1S6sVdi7-bb7Cm#ec2-107-20-245-109.compute-1.amazonaws.com:5432/dc2kahsue8hn20. Valid options are: DATABASE_URL, HEROKU_POSTGRESQL_AQUA_URL
My command,however,always returns this to me.
Unknown database: postgres://xxxxxxxxx:xxxxxxxxxxxxxxx#xxx-xxx-xx-xxx-xxx.compute-1.xxxxxxx.com:xxxx/xxxxxxxxxxxxxx. Valid options are: DATABASE_URL, HEROKU_POSTGRESQL_AQUA_URL
What should I do? Could you give me some advice?
You should use:
heroku pg:reset HEROKU_POSTGRESQL_AQUA
I know this question is old, but as I've just been through this, here is what I did:
heroku pg:reset HEROKU_POSTGRESQL_HEROKUCOLOR_URL --confirm {app_name}
heroku run rake db:schema:load
heroku run rake db:migrate
heroku run rake db:seed
As per: Heroku rake db:migrate does not create tables (Rails 5)
I am attempting to reset my database on heroku using this:
heroku pg:reset SHARED_DATABASE
and then run:
heroku run rake db:create db:migrate db:seed
But I am getting the following error:
Validation failed: Email has already been taken
I have noticed by going into the heroku rails console that the users are not being dropped and thus this validation has failed. What am I missing here?
Try this:
heroku pg:reset SHARED_DATABASE --confirm {the name of your app}
Substitute the name of your app where I have written {the name of your app}. For example, if your app is called my_great_app then you use:
heroku pg:reset SHARED_DATABASE --confirm my_great_app
To recreate the database with nothing in it:
heroku rake db:migrate
To populate the database with your seed data:
heroku rake db:seed
You can combine the last two into one action by executing this:
heroku rake db:setup
I've just been through this, here is what I did (step #3 was missing from the other answers which stalled me for a while):
heroku pg:info (to get the value of HEROKU_POSTGRESQL_HEROKUCOLOR_URL)
heroku pg:reset HEROKU_POSTGRESQL_HEROKUCOLOR_URL --confirm {app_name}
heroku run rake db:schema:load
heroku run rake db:migrate
heroku run rake db:seed
As per: Heroku rake db:migrate does not create tables (Rails 5)