Rails Basecamp样式子域的最佳实践 [英] Rails Basecamp style subdomains best practice

查看:58
本文介绍了Rails Basecamp样式子域的最佳实践的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的目标是为每个子域拥有单独的用户帐户.在任何情况下都不要在子域之间进行异花授粉.

My goal is to have separate user accounts for each subdomain. Under no circumstance do I want cross-pollination between subdomains.

我查看了 Robby Russle DHH的想法(虽然都是在Rails3之前).

I've looked over Robby Russle, and DHH's thoughts (both are pre-Rails3 though).

控制器处理非常简单,我的问题是关于保持模型的数据分离.阻止user1查看user2数据的最佳方法是什么?

The controller handling is pretty straight forward, my questions is about keeping the model's data separated. What's the best way to keep user1 from seeing user2's data?

一些想法可能包括:

  1. 向每个模型添加subdomain_id外键- Advantage ,可以使用简单的一对多关系将每个模型的作用域限定为一个子域. -缺点,这是数据与较大的应用程序逻辑之间的紧密结合,这似乎是不合适的.

  1. Add a subdomain_id foreign key to every model - Advantage, simple one-to-many relationship can be used to scope each model to a subdomain. - Disadvantage, this is pretty tight coupling between the data and the larger application logic, which seems inappropriate.

One-to-many :through与子域- Advantage 关联的模型,无需在现有表中添加subdomain_id外键列,即可将它们与其子域关联. -劣势,我的直觉是这太过分了.多个联接查询可能会变得很复杂,并且可能会出现异花授粉的错误.

One-to-many :through for each model associating it with a subdomain - Advantage, no need to add a subdomain_id foreign key column to existing tables associating them with their sub domain. - Disadvantage, My gut feeling is that this is way overkill. Multiple join queries may get complicated and cross-pollination bugs may occur.

每个子域的单独应用程序或数据库- Advantage ,数据完全隔离. -缺点,需要管理/更新/保护/托管/托管大量单独的应用程序/数据库.

Separate applications or databases for each subdomain - Advantage, the data is completely segregated. - Disadvantage, a large number of individual applications/databases will need to be managed/updated/secured/hosted/etc.

您的想法?

推荐答案

选项5.

Option 5. Guy Naor's Schema solution - Advantage, This just blew my mind. Mostly transparent to rails, COMPLETE data separation, only one database, works really great for applications that weren't originally designed as multi-tenant. a-mazing. - Disadvantage, need to be using Postgres, or some other database that supports schemas (I'm already using PG anyway), you'll need to iterate over existing schemas when you migrate.

目前,这似乎是最好的方法.有什么主要的缺点吗?.

Right now this seems far and away the best way. Are there any major drawbacks?.

这篇关于Rails Basecamp样式子域的最佳实践的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆