Different organization data separation

What is best practice to store separate organization data in one database? One solution is totally hardware separation in different databases, which is too much overhead for maintenance. Second is different schemas, I am not sure how to set it up in rails. Third could be default_scope which always relies on some variable with current organization filter. What are other options to separate and avoid leakage of one organization to another?

You may want to look at the apartment gem, and also the ebook Multi-tenancy with Rails.

thank you, it looks like exactly what I need.

@uzzer there may be a legal requirement for multi-tenancy in your application, but if there isn’t I’d also suggest that you explore keying the data with an organization_id and then using scopes to prevent users from seeing data that’s not theirs. So in your PostsController, the index would look like:

def index
  @posts = current_user.organization.posts

The work to maintain a multi-schema setup is a lot of ongoing effort, and is possibly not worth the cost to maintain.

1 Like