Resetting database on heroku - ruby-on-rails

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)

Related

How reset Heroku PG DB via Heroku Scheduler?

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

Command to run heroku run rake db:migrate on production db when you also have a staging db in heroku

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

Rake db:reset 'user does not have CONNECT privilege'

So I'm using Heroku Postgres in my Rails app, but I'm not hosting my app on Heroku itself. I used the Active Record connection details from Heroku in my database.yml, and it looks like this:
development:
adapter: postgresql
encoding: unicode
pool: 5
database: [database]
username: [username]
password: [password]
host: ec2-54-227-243-78.compute-1.amazonaws.com
port: 5432
However, now I'm trying to rake db:migrate my app so the database gets all set up with my models. Running that command doesn't do anything, so I tried rake db:reset and I get this:
Couldn't drop df2cokjfj0k4vu : #<PG::Error: FATAL: permission denied for database "postgres"
DETAIL: User does not have CONNECT privilege.
df2cokjfj0k4vu already exists
-- initialize_schema_migrations_table()
-> 1.3997s
-- assume_migrated_upto_version(20130924040351, ["/home/action/braindb/db/migrate"])
-> 0.0882s
Any idea what I'm doing wrong. I'm still pretty new to Rails so sometimes I forget how to get my Postgres database setup properly when migrating hosts.
Use heroku pg:reset DATABASE instead as noted in https://devcenter.heroku.com/articles/rake
You cannot drop databases in Heroku with rake db:reset because user has no privileges.
You can't drop your PG database on Heroku.
I recently had this problem and resolved it through the following steps.
heroku pg --help gets the name of commands for using postgres
heroku pg:reset DATABASE # resets the db
Answer the prompt to confirm
Like others I had a similar problem but running pg:reset did not help: that's where I ran into the user does not have CONNECT privilege issue.
1) heroku pg:reset you will be prompted to enter the project name to confirm.
2) From Heroku's docs run heroku rake db:schema:load
I had the same problem. I fixed it by running:
heroku pg:reset DATABASE
(note: must specify DATABASE as above)
If you got this because you were running rake db:create, instead, simply skip to the migration. For whatever reason, postgresql on heroku doesn't require the rake db:create step as may be required on local installations.
In other words, instead of
heroku run rake db:create db:migrate db:seed
run this instead
heroku run rake db:migrate db:seed
The solution to me was to just go straight to migration because the database is already created (don't go on "heroku run rails db:create")
heroku run rails db:migrate -a YOURAPPNAME
For one of my apps, upgrading to the first paid tier of a Heroku database seemed to work for me: https://devcenter.heroku.com/articles/upgrade-heroku-postgres-with-pgbackups#provision-new-plan
Reason was that 'heroku pg:info' revealed that I was over my row limit as shown here:
Rows: 12392/10000 (Write access revoked)

Heroku won't reset my database

I have been trying to run $ heroku pg:reset from the command line but I believe I'm not putting in the database correctly. I've tried a number of variations.
I ran $ heroku config | grep POSTGRESQL to get the database name which prints as
HEROKU_POSTGRESQL_PINK_URL: postgres://naknaswvxfvuup:QK2dHYNMZ_va10lDgMDo4S0BIM#ec2-23-21-161-255.compute-1.amazonaws.com:5432/db7eute4gu4mcb
I've tried running everything from
#1
$ heroku pg:reset HEROKU_POSTGRESQL_PINK_URL: postgres://naknaswvxfvuup:QK2dHYNMZ_va10lDgMDo4S0BIM#ec2-23-21-161-255.compute-1.amazonaws.com:5432/db7eute4gu4mcb
#2
$ heroku pg reset postgres://naknaswvxfvuup:QK2dHYNMZ_va10lDgMDo4S0BIM#ec2-23-21-161-255.compute-1.amazonaws.com:5432/db7eute4gu4mcb
#3
$ heroku pg:reset db7eute4gu4mcb
and other variations. Please let me know how to correctly note this as I keep getting either an error or this text from the commmand line " ! Unknown database: db7eute4gu4mcb. Valid options are: DATABASE_URL, HEROKU_POSTGRESQL_PINK_URL"
I'm currently at 10.4 on the Ruby on Rails tutorial. Thanks!
You should specify a DATABASE when run heroku pg:reset. This is the syntax:
heroku pg:reset <DATABASE>
To know the value of , you can run:
heroku pg:info
It will return DATABASE_URL, something like: HEROKU_POSTGRESQL_GRAY_URL
Then you can reset your database:
heroku pg:reset HEROKU_POSTGRESQL_GRAY_URL
In your case, to reset database run:
heroku pg:reset HEROKU_POSTGRESQL_PINK_URL
this is how it worked for me
(replace app-staging with your app's name, do not replace DATABASE_URL, this is how heroku now finds the app's db)
heroku pg:reset DATABASE_URL --confirm app-staging
hope it helps
Assuming you have your authentication information exported to the shell environment, you should be fine with just passing the name of the database. For example:
PGPASSWORD='foobarbaz'
export PGPASSWORD
heroku pg:reset pink
There are certainly other ways to use the reset command, but IMHO this is the easiest.

Heroku not resetting database

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)

Resources