简体   繁体   中英

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. Can Rails6's multi-database feature dynamically recognize a new database if it's added while the application is running?

If anyone knows, please advise.

Have you looked into apartment gem ? It has API to create new DBs during runtime and switch to them. I have used it successfully on rails 5.2 but haven't tried on 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. Hope this helps and good luck!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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