简体   繁体   English

如何在 Rails6 中实现数据库级多租户功能,允许我在运行时动态添加数据库?

[英]How can I implement a database-level multi-tenancy feature in Rails6 that allows me to dynamically add databases in runtime?

I want to implement a database-level multi-tenancy feature that allows me to add databases dynamically.我想实现一个允许我动态添加数据库的数据库级多租户功能。 I haven't found a way to do this in Rails6.我还没有找到在 Rails6 中执行此操作的方法。 Can Rails6's multi-database feature dynamically recognize a new database if it's added while the application is running? Rails6 的多数据库特性能否在应用程序运行时动态识别新数据库?

If anyone knows, please advise.如果有人知道,请指教。

Have you looked into apartment gem ?你看过公寓宝石吗? It has API to create new DBs during runtime and switch to them.它有 API 在运行时创建新的数据库并切换到它们。 I have used it successfully on rails 5.2 but haven't tried on rails 6 (YMMV).我已在 rails 5.2 上成功使用它,但尚未在 rails 6 (YMMV) 上尝试过。 You can also leverage Rails 6's multi-database feature to create and switch to DBs in runtime (requires little bit of in depth Rails connection pool knowledge), but when I tried with rails 6.0, I was forced to establish new connection on every request, which made things slow and unusable.您还可以利用 Rails 6 的多数据库功能在运行时创建和切换到 DB(需要一点深入的 Rails 连接池知识),但是当我尝试使用 rails 6.0 时,我被迫在每个请求上建立新连接,这使事情变得缓慢且无法使用。 Hope this helps and good luck!希望这会有所帮助,祝你好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM