TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Building secure Multi-tenant applications in Elixir

6 点作者 sheharyarn大约 4 年前

2 条评论

sheharyarn大约 4 年前
This obscure little feature in Ecto&#x2F;Elixir is something we&#x27;ve been using at Slab.com for about a year. While the blog post only covers the feature itself, I wanted to give a better overview of *WHY* we&#x27;re using it.<p>Slab is a multi-tenant Phoenix app where all tables in our database, including pivot tables, have an `org_id` foreign key that references the team the data belongs to. Using association defaults enforces that the correct `org_id` value is automatically set for all resources.<p>We combine this with an `OrgRepo` module that wraps around our default `Repo`, which can only write or read other resources with the same `org_id`, ensuring that data for one team has no possibility of accidentally leaking to another team (using `Repo` is forbidden in our codebase).<p>An added bonus is; when we eventually have to scale our databases via something like sharding and have to vertically partition the data based on `org_id`, we would already have this system in place to support us.
nickjj大约 4 年前
I&#x27;d be curious how this compares to Ecto.Repo.prepare_query&#x2F;3 at <a href="https:&#x2F;&#x2F;hexdocs.pm&#x2F;ecto&#x2F;multi-tenancy-with-foreign-keys.html#content" rel="nofollow">https:&#x2F;&#x2F;hexdocs.pm&#x2F;ecto&#x2F;multi-tenancy-with-foreign-keys.html...</a> which sets you up for foreign key based multi-tenancy that can be enforced automatically in most common cases.<p>Is your strategy meant to be an alternative to prepare_query?
评论 #26627870 未加载