Rails 迁移目标特定数据库
在我的 Rails 应用程序中,我引用了多个数据库。使用 connection_ninja 我告诉模型指向哪里,但是如何对迁移执行相同的操作?
RAILS_ENV
不起作用,因为特定迁移需要指向特定数据库
提前致谢, Justin
UPDATE--------------
我发现 ActiveRecord::Migration 不支持 built_connection
(conn_ninja 的基础并连接到其他数据库),即使该方法是ActiveRecord::Base 的一部分。
关于如何解决这个问题有什么想法吗?
In my rails app, I reference multiple databases. Using connection_ninja I tell models where to point, but how do I do the same for migrations?
RAILS_ENV
doesn't work since specific migrations need to point to specific DBs
Thanks in advanced,
Justin
UPDATE--------------
I discovered establish_connection
(basis for conn_ninja & connected to other dbs) is not honored by ActiveRecord::Migration even though the method is part of ActiveRecord::Base.
Any ideas on how to hack around this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有点老了,但我最近为此苦苦挣扎,最终发现不仅仅是一个黑客,而是一个实际的解决方案。
技巧是使用模型连接而不是修改 ActiveRecord::Base 连接,这会在更新 schema_migrations 时导致迁移后出现问题。
看看这里:https://stackoverflow.com/a/34292909/2499227
A bit of an old one, but I struggled with this recently and finally discovered not just a hack, but an actual solution.
The trick is to use a Model connection instead of modifying the ActiveRecord::Base connection which will cause issues after the migration when schema_migrations are updated.
Take a look here: https://stackoverflow.com/a/34292909/2499227
ActiveRecord::Migration
仅使用ActiveRecord::Base
,因此您应该假设能够放置use_connection_ninja(:group)
在您的迁移中ActiveRecord::Migration
just usesActiveRecord::Base
so you should hypothetically be able to putuse_connection_ninja(:group)
in your migration