还有一个基于上述技术的多租户宝石。它被称为 Apartment 但我只是在我的应用程序中手动实现了一些东西,因为它只需要大约 20 行代码我想要什么 vs 相信宝石可以完成所有巫术:)
For those that are contemplating this. Turns out it is much easier to implement this using PostgreSQL schema's. It's called multi-tenanting and with postgres you can have one database (defined in database.yml) and multiple schema's within that database which are essentially just namespaces. Each schema has its own tables etc... and you can create, switch between and delete them on the fly. Make sure you use at least Rails 3.1.1 as prepared statements apparently wreaks havoc with database and schema switching. There are also some fixes in Rails master as of writing that address some minor issues with schemas.
There is also a gem out there for multi-tenanting based on the above technology. It's called Apartment but I just implemented things manually in my app as it was only about 20 lines of code to do what I wanted vs trusting a gem to do all the voodoo :)
发布评论
评论(1)
对于那些正在考虑这一点的人。事实证明,使用 PostgreSQL 模式来实现这一点要容易得多。这称为多租户,使用 postgres,您可以拥有一个数据库(在database.yml 中定义)和该数据库中的多个模式,这些模式本质上只是命名空间。每个模式都有自己的表等...您可以动态创建、切换和删除它们。确保至少使用 Rails 3.1.1,因为准备好的语句显然会对数据库和模式切换造成严重破坏。截至撰写本文时,Rails master 中还进行了一些修复,解决了架构的一些小问题。
还有一个基于上述技术的多租户宝石。它被称为 Apartment 但我只是在我的应用程序中手动实现了一些东西,因为它只需要大约 20 行代码我想要什么 vs 相信宝石可以完成所有巫术:)
For those that are contemplating this. Turns out it is much easier to implement this using PostgreSQL schema's. It's called multi-tenanting and with postgres you can have one database (defined in database.yml) and multiple schema's within that database which are essentially just namespaces. Each schema has its own tables etc... and you can create, switch between and delete them on the fly. Make sure you use at least Rails 3.1.1 as prepared statements apparently wreaks havoc with database and schema switching. There are also some fixes in Rails master as of writing that address some minor issues with schemas.
There is also a gem out there for multi-tenanting based on the above technology. It's called Apartment but I just implemented things manually in my app as it was only about 20 lines of code to do what I wanted vs trusting a gem to do all the voodoo :)