Rails - Access Heroku DB from another rails app

Viewed 14

I have two applications deployed in heroku which have their own pg database. I wonder is there a way so that one application can have the access to the db of other application without storing values in its own db.

1 Answers

The database.yml looks like this:

production:
  primary:
    database: my_primary_database
    username: root
    password: <%= ENV['ROOT_PASSWORD'] %>
    adapter: mysql2

  secondary:
    database: my_secondary_database
    username: secondary_root
    password: <%= ENV['SECONDARY_ROOT_PASSWORD'] %>
    adapter: mysql2
    migrations_paths: db/animals_migrate

Your model should have below:

class Order < ApplicationRecord

  connects_to database: { writing: :secondary }
end

Please have a look at the below documentation. https://guides.rubyonrails.org/active_record_multiple_databases.html

I hope this will help you with what you want to achieve.

Related