Can you run the heroku console based on a serial DB?

I have a ruby ​​on rails application deployed on heroku with a database and a subscriber database.

I usually do a "geku run rails console" to look around the data, and I wonder if there is a way I can do this in the followers database so that I don't accidentally write / delete things. I know this should be simple, but I could not find the documentation on it.

Thanks!

+6
source share
5 answers

You can do this on your local console. Just run it:

rails console 

Then you need the connection information for your heroku subscribers database. You can get this from https://postgres.heroku.com/databases/ . Just click on the appropriate database and assign a hash with the following information:

 follower_db = {:adapter => "postgresql", :host => "myhost", :username => "myuser", :password => "mypass", :database => "somedatabase"} 

Now connect to this remote database from the console:

 ActiveRecord::Base.establish_connection(follower_db) 

Now any request that you enter in the console will be launched in this database.

+4
source

The console, of course, has its place, but if I want to check what data is in the database, I would rather look directly at it without activating ActiveRecord, etc. I found many cases where using the console requires you to check the generated SQL code anyway to make sure there are no areas in it (for example).

I would suggest that you try to get used to using the SQL interface (perhaps PgAdminIII) ​​instead of the console - the Heroku data file will work even if you do not want to worry about connecting to the client (although the psql connection string is provided to you from the database page).

0
source

If you are concerned about accidentally deleting files, start the console with the sandbox flag

 heroku run console --sandbox --app app-name 

Your changes will be discarded when your session ends.

0
source

This will use the tracking element database credentials from the FOLLOWER_DATABASE_URL environment variable in your Heroku application to launch the Rails console, which connects directly to the successor, and not to the advanced database. Normally, Rails is configured to read from DATABASE_URL by default, and this simply sets it to a different value for the duration of the console session.

heroku run 'DATABASE_URL=$FOLLOWER_DATABASE_URL rails console'

0
source

A database follower is a read-only copy of the main database that remains relevant with the main database data. Since records and other data changes are recorded in the main database, the changes are transferred in real time to the subscriber database.

Source - https://devcenter.heroku.com/articles/heroku-postgres-follower-databases

-1
source

Source: https://habr.com/ru/post/954740/


All Articles