NoBrainerORM / nobrainer

Ruby ORM for RethinkDB
http://nobrainer.io/
Other
387 stars 49 forks source link

NoBrainer.connection not using RDB_HOST/RDB_AUTH/RDB_DB tuple in rails console #161

Closed piemont closed 9 years ago

piemont commented 9 years ago

I have nobrainer 0.29.0 with rails 4.2.4. I've set RDB_HOST, RDB_AUTH, and RDB_DB to point to a RethinkDB server on EC2.

When I launch my rails app via rails server and send a GET request that requires querying RethinkDB, NoBrainer correctly generates a connection to EC2, with the following output:

Started GET "/api/accounts.json" for ::1 at 2015-09-14 19:19:28 -0700
Processing by Api::AccountssController#index as JSON
Connected to rethinkdb://****@ec2-12-34-56-789.us-west-2.compute.amazonaws.com:28015/anonymized_db

However, when I enter the rails console via rails console, NoBrainer does not pick up the environment variables to configure the connection URI:

Daniels-Computer:appdirectory danielp$ rails console
Loading development environment (Rails 4.2.4)
irb(main):001:0> ENV['RDB_HOST']
=> "ec2-12-34-56-789.us-west-2.compute.amazonaws.com"
irb(main):002:0> ENV['RDB_DB']
=> "anonymized_db"
irb(main):003:0> ENV['RDB_AUTH']
=> "1a2b3c4d5e6f7g8h9i0j"
irb(main):004:0> NoBrainer.connection
=> #<NoBrainer::Connection:0x007fc003bc0a50 @orig_uri="rethinkdb://localhost/myapp_development", @parsed_uri={:auth_key=>nil, :host=>"localhost", :port=>28015, :db=>"myapp_development"}>

Therefore when I try to execute a NoBrainer query from the console, the connection is refused (as there is no DB running at localhost:28015):

irb(main):005:0> Account.count
[   5.4ms] r.table("accounts").count -- Errno::ECONNREFUSED Connection refused - connect(2) for "localhost" port 28015
Errno::ECONNREFUSED: Connection refused - connect(2) for "localhost" port 28015

Why does my database configuration via environment variables not work in console? I have tried doing this configuration both manually in the linux shell, and via secrets.yml.

nviennot commented 9 years ago

Can you run http://tmate.io/ and share your terminal with me? (you may send the connection string via email). This way it will be easier to debug :) Thank you

nviennot commented 9 years ago

The culprit was spring. Use DISABLE_SPRING=1 to disable spring.