gpt4 book ai didi

ruby-on-rails - 具有不同架构的多个数据库的 rake 任务

转载 作者:行者123 更新时间:2023-12-04 04:23:07 26 4
gpt4 key购买 nike

我正在开发一个多数据库Rails 3应用程序。每个数据库都有不同的架构(生产环境中的数据库位于不同的位置)。我将应用程序设置为与不同的数据库进行对话,如下所示:

数据库

development:
adapter: mysql2
encoding: utf8
reconnect: false
database: main_development
pool: 5
username: someuser
password: somepassword
socket: /tmp/mysql.sock

other_development:
adapter: mysql2
encoding: utf8
reconnect: false
database: other_development
pool: 5
username: someuser
password: somepassword
socket: /tmp/mysql.sock

型号/other_base.rb
class OtherBase < ActiveRecord::Base
self.abstract_class = true
establish_connection "other_#{Rails.env}"
end

型号/some_model.rb
class SomeModel < OtherBase
# Regular stuff here
end

现在,这对于Web应用程序可以正常工作,但对于运行rake任务(包括测试)(夹具未正确加载)而言效果不佳。有没有可用的 gem ?任何帮助表示赞赏。

另外,最好创建一个schema.rb文件,该文件可以处理不同DB的不同模式-也就是说,允许我执行rake db:create或db:setup之类的事情,并让它与数据库一起创建多个数据库特定的架构。

最佳答案

在这种情况下,我发现环境的使用是 Not Acceptable 。您要在同一环境中拥有两个数据库。

当我自己研究这个问题时,我遇到了github用户rafaelchiti的要旨。不幸的是,他删除了原始要点。您可以找到copy of it here

关于ruby-on-rails - 具有不同架构的多个数据库的 rake 任务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5086334/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com