neo4jrb / activegraph

An active model wrapper for the Neo4j Graph Database for Ruby.
http://neo4jrb.io
MIT License
1.4k stars 276 forks source link

Database URL not being passed through from neo4j.yml for "rake tasks" or "bin/rails tasks" #1556

Closed mvuk closed 5 years ago

mvuk commented 5 years ago

Overview

When developing locally in development, I have no issues. I have my neo4j.yml file set to the following, where it starts up.

development:
  type: http
  url: http://neo4j:password@localhost:7474

I have another environment, called "demo".

demo:
  type: http
  url: <%= ENV["DB_URL"] %>

Where things go wrong

The "DB_URL" value that I pass through evaluates to http://neo4j:password@db:7474 which I have set up in the appropriate docker-compose.yml file.

When I am starting up, I wrote a script that when rails initializes that it will run migrations on the database. When my rails application runs to start up, I see the following response in the console:

web_1  | ETHON: performed EASY effective_url=http://localhost:7474/db/data/schema/constraint response_code=0 return_code=couldnt_connect total_time=0.004811
web_1  |  HTTP REQUEST: 8ms GET http://localhost:7474/db/data/schema/constraint (0 bytes)

You will notice that the GET request is pointing to localhost:7474 instead of db:7474. I have even tried not using "db" and configured it to point at other ports (eg. localhost:8320) however it is always evaluating to localhost:7474.

Where things go right

So then I wonder, why doesn't the proper database URL pass through? Once that rake task is run, "rails s" runs to start up the rails server. The server successfully starts, and my application is able to display its home screen! When I look at my "demo.log" file, I see the following:

D, [2019-07-01T17:19:14.321175 #220] DEBUG -- : ETHON: performed EASY effective_url=http://db:7474/db/data/transaction/commit response_code=200 return_code=ok total_time=0.005891
D, [2019-07-01T17:19:14.321789 #220] DEBUG -- :  HTTP REQUEST: 7ms POST http://db:7474/db/data/transaction/commit (1 bytes)

This means 200 success! You will also notice that it is calling db:7474 and not localhost:7474. So the application itself knows the correct url but when I try to run the task such as "bin/rails neo4j:schema:load[true]" or "rake neo4j:migrate" then it insists on once again only using "localhost:7474" and never the url which I assigned to it.

I can even SSH into that docker container, and then manually run one of these neo4j tasks again, and it will start looking for localhost:7474 again.

I look through my configuration files, and nowhere do I hard code in a "localhost:7474".

So my next logical question is: could it be that the "localhost:7474" is being hard-coded in somewhere? Would that direct me to a solution here?

Runtime information:

Neo4j database version: neo4j gem version: 9.5 neo4j-core gem version:

amitsuryavanshi commented 5 years ago

@mvuk Looking at your gitter comment I solved my issue by making sure to include config.neo4j.session.type = :http config.neo4j.session.url = ENV["DB_URL"] in the application.rb, looks like you have resolved this. Closing this, feel free to reopen if still facing issue. Thanks.