初始化程序或环境代码中的 Rails 数据库连接
我一直在尝试在 EngineYard 上托管一个应用程序,但在连接到外部数据库(未托管在 EngineYard 上)时遇到了问题。
我刚刚收到 engineyard 的回复,他们在自己的一端重新创建了 database.yml 文件,结果,远程数据库连接详细信息丢失了。
来自EngineYard的回应
我们部署过程的一部分将编写一个database.yml 文件,以便您可以连接到我们为您配置的数据库。如果您通过 SSH 连接到您的实例,您可以在 /data/mls_data_norm/current/config/database.yml 中看到我们为您编写的实例。
如果您想对此进行配置,您将需要执行以下两项操作之一。一种是设置一个不同的初始化程序或环境代码来连接到另一个数据库。另一种(可能也是首选)是使用自定义 Chef 食谱来执行此操作。您可以在此处阅读有关执行此操作的更多信息: http://docs.engineyard.com/custom-chef-recipes.html
我不知道我将在engineyard 上托管多久,而且我不喜欢在本地运行与生产中不同的代码的想法。整个“食谱”的事情让我觉得我会重写这个连接。
我确信有一种方法可以在database.yml 文件之外定义数据库连接,但我不知道如何做,而且到目前为止我的搜索没有发现任何结果。
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 environment 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
database.yml 的唯一目的是保留连接参数,并且因为 EngineYard 做了一些愚蠢的事情,但这并不意味着您需要将连接参数移动到其他地方。
最好的解决方案是您自己负责部署。花几个小时阅读
capistrano
文档,您就可以开始了。它简单、优雅,而且功能更强大。您很快就会使用 capistrano 做比主机提供的更多与部署相关的事情。https://github.com/capistrano/capistrano/wiki
其他选项包括在部署后运行脚本这再次覆盖database.yml并重新启动服务器。
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.