开发者

Rails database connection in initializer or environment code

开发者 https://www.devze.com 2023-03-11 10:15 出处:网络
I\'ve been trying to get an app hosted on EngineYard, and have run into a problem connecting to an an external database (not hosted on engineyard).

I've been trying to get an app hosted on EngineYard, and have run into a problem connecting to an an external database (not hosted on engineyard).

I just got a response from engineyard that they re-create the database.yml file on their end, and as a result, the remote database connection details are lost.

Response from EngineYard

Part of our deploy process will write out a database.yml file so that you can connect to the database we configure for you. If you SSH into your instance, you can see the one we write for you at /data/mls_data_norm/current/config/database.yml.

If you want to configure this, you will need to do one of two things. One is to set up a different initializer or e开发者_如何学Cnvironment code that will connect to this other DB. The other (and probably preferred) is to use a custom Chef recipe to do this. You can read more about doing that here: http://docs.engineyard.com/custom-chef-recipes.html

I don't know how long I'll be hosting on engineyard, and I don't like the idea of running different code locally than in production. The whole 'recipes' thing, makes me think that down the line I'll be rewriting this connection.

I'm sure there is a way to define a database connection outside the database.yml file, but I don't know how, and my searches so far have turned up nothing.


The sole purpose of database.yml is to keep connection parameters, and because EngineYard does some silly stuff, does not mean that you need to move your connection parameters to some place else.

The best solution would be to take care of your deployment yourself. Spend a couple of hours reading capistrano documentation and you would be ready to go. It is simple, elegant and much more powerful. You would soon be doing a lot more deployment related stuff using capistrano than what your host provides.

https://github.com/capistrano/capistrano/wiki

Other options include running a script post deployment that again overwrites the database.yml and does a server restart.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号