mercredi 6 mai 2015

Get Postgres-activerecord setup to work both locally and in Heroku

I'm automating DB creation (with a Rakefile in a Sinatra App).

I would like to be able to run the rakefile from my Linux user "pete" (eg pete@pete_laptop: /path $ rake db:create) AND from Heroku.

It comes down to the settings in my config/database.rb:

ActiveRecord::Base.establish_connection(
  :adapter  => db.scheme == 'postgres' ? 'postgresql' : db.scheme,
  :host     => db.host,
  :port     => db.port,

  # pete@ubuntu_14.04_laptop--------
  # :username => 'pete',
  # :password => 'password',
  # OR
  # heroku -----------------
  # :username => db.user,
  # :password => db.password,

  :database => DB_NAME,
  :encoding => 'utf8'
)

If I use the pete@ubuntu_laptop settings, the database works in localhost but not in Heroku, If I use the heroku settings, the database works in localhost but not in Heroku.

How can I setup this file/my ubuntu laptop so that the app works both on localhost & in Heroku?

Cheers,

Pete

Aucun commentaire:

Enregistrer un commentaire