jeudi 2 juillet 2015

Establish external database connection in production on Heroku

I am trying to establish a connection to a secondary, external database on Heroku (this is a PostgreSQL db running on AWS). I am trying to find the easiest and/or best way to do this.

I have tried using a Capistrano task to copy the database.yml file during deployment to Heroku:

after "deploy:update_code","deploy:config_symlink"

namespace :deploy do

  task :config_symlink do
    run "cp #{shared_path}/shared/config/database.yml #{release_path}/config/database.yml"
  end
end

I have tried establishing the connection via Heroku config vars:

class Pgdb < ActiveRecord::Base.establish_connection(
    :adapter => ENV['PG_ADAPTER'],
    :database => ENV['PG_DB'],
    :username => ENV['PG_USER'],
    :password => ENV['PG_PW'],
    :host => ENV['PG_HOST']
  )

  self.abstract_class = true
  self.table_name = 'test'

  def self.getCardInfo(card_name)
    get = connection.query("SELECT * FROM test)
    get
  end
end

I can't find any documentation that makes sense or tells me exactly how to do this. I do not know if I'm close or way off in the attempts above. I'm looking for any solution that fixes the above attempts or any other solution to this problem.

Aucun commentaire:

Enregistrer un commentaire