根据应用程序的启动方式设置数据库
我有两个 Rails 应用程序(我们称它们为 APP-1 和 APP-2),每个应用程序都依赖于第三个 Rails 应用程序 (APP-3)。
我希望能够在我的 CI 服务器上并行运行 APP-1 和 APP-2 的测试。问题是,两者都需要启动 APP-3 并通过 APP-3 写入数据库。如果测试并行运行,这会导致冲突和失败。
我的解决方案的想法是让 APP-1 和 APP-2 各自启动自己的 APP-3 实例,并使每个实例指向不同的数据库。有没有办法在APP-3的database.yml中动态设置数据库,以便根据哪个APP启动它连接到不同的数据库?
供参考。 APP-1 和 APP-2 当前通过 rake 任务启动 APP-3。
I have two Rails applications (lets call them APP-1 and APP-2), each of them has a dependancy on a third Rails application (APP-3).
I would like to be able to run the tests for APP-1 and APP-2 in parallel on my CI server. The problem is, both need to start up APP-3 and write to a DB via the APP-3. This causes conflicts and failures if the tests are run in parallel.
My idea for a solution is for APP-1 and APP-2 to each start their own instance of APP-3 and to have each instance point to a different DB. Is there a way to dynamically set the DB in the database.yml of APP-3 so that it connects to a different DB depending on which APP starts it up?
FYI. APP-1 and APP-2 currently start APP-3 via rake tasks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为App-3 制作两个database.yml 文件。将它们命名为database_A.yml 和database_B.yml 或任何你想要的名称。
在 App-3 的environment.rb 文件中,将以下内容添加到初始化程序块的末尾。
我从我的博客中提取了此内容,其中描述了当我使用 JRuby 启动应用程序时如何使用不同的 database.yml 文件。这个概念很相似,所以希望这对您有所帮助。
http://www .workingasintending.com/2010/05/03/choosing-a- Different-rails-databaseyml-file-for-jruby/
Make two database.yml files for App-3. Call them database_A.yml and database_B.yml or whatever you want.
In your environment.rb file for App-3, add the following toward the end of the Initializer block.
I pulled this from my blog, where I describe how I use a different database.yml file when I launch my app with JRuby. The concept is similar, so hopefully you find this helpful.
http://www.workingasintended.com/2010/05/03/choosing-a-different-rails-databaseyml-file-for-jruby/