4

I am using Salesforce for my CRM, but need to query data (multiple records, so no Zapier) for a Heroku based Sinatra app. Heroku provides a service that replicates Salesforce objects to Postgres tables regularly which gets my data out of Salesforce.

I've coded a Sinatra app before and hosted it on Heroku so I'm a bit familiar with the process of setting up a dev db locally then pushing it to production via the many tutorials. However, i'm running into an issue finding any information that will allow me to connect to the existing production Postgres DB that already is populated with the data I need while having no need to create and connect to a local dev db.

Heroku provides me with the following enter image description here

How and where to I plug in these various credentials securely so my following files have the right information to connect to tables Venue__c and Spaces__c?
app.rb
/config
- database.yml
- environments.rb

3 Answers 3

3
+25

Assuming that you have ActiveRecord, it should just be a case of configuring your database.yml correctly. For example, to directly connect your development environment, use something like:

# database.yml
development:
  adapter: postgresql
  encoding: unicode
  database: your_database
  username: your_user
  password: your_password
  host: your_host
  port: your_port

# or alternatively, using the URI
development:
  url: postgres://your_user:your_password@your_host/your_database
Sign up to request clarification or add additional context in comments.

7 Comments

Is it a necessity to create a development db? Is your solution suggesting I can use the live Heroku Postgres db as my development db? I am using ActiveRecord, but I have not run any rakes, is that something I need to do considering this db automatically had data pushed to it on a regular basis?
@csakon: yes, this would connect directly to the DB on Heroku. If you need a dev database there are a few options. You could set up a secondary Salesforce account and set up a new Postgres DB for it to sync with, and develop on top of that. Or if you don't care about sync then you can set up a local Postgres DB and import your data from live to dev (see here for more details: devcenter.heroku.com/articles/…)
I don't care about having a dev db environment really (your code should maybe say 'production:'? But more importantly, the issue i'm having is the connection, I already had the code you provided above, but it's just not connecting (Internal Server Error). I'm wondering if there is something different I do if i'm connecting to an existing db with existing data vs setting one up from scratch.
development was intentional here, to allow your dev server to connect to the DB; but you could certainly use production too if you run your server in production mode. I would recommend running locally in dev mode and then posting up the logs - it should give you a much more informative error than "internal server error"
I'm getting an ActiveRecord::NoDatabaseError at /ra054100000DMnRF/chad/stinson FATAL: role "your_username" does not exist which you can see here: evernote.com/shard/s2/sh/b36d645d-3f86-4f8c-af01-1f019d97c9ea/…
|
0

Heroku publishes your database credentials to you through a URL in an environment variable. You should be able to access it through ENV.fetch("DATABASE_URL"). Depending on your ORM you will use different ways to connect to your database, e.g. Sequel is able to use this value directly as a parameter to Sequel.connect(ENV.fetch("DATABASE_URL")).

As you seem to use ActiveRecord you could be using ActiveRecord::Base.establish_connection(...) as suggested in this post which also exemplifies how to parse the URL (which might not be necessary anymore). This does not translate directly to a database.yml, but since you do not plan to use Rails you will have to provide your own version of environment.rb or some such and it should be easy enough to do in that place.

Comments

0

Turns out Heroku has a great tutorial that not only connects to the replicated database, but is also written for Sinatra.

https://devcenter.heroku.com/articles/getting-started-with-heroku-and-connect-without-local-dev#introduction

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.