简体   繁体   English

具有共享数据库和鉴别器列的多租户

[英]Multi-Tenant with shared database and discriminator column

Hibernate Multi-tenant Shared Database (discriminator column) until now still not implemented. Hibernate 多租户共享数据库(鉴别器列)至今仍未实现。

I'm working on a Quarkus RestEasy JAX-RS endpoint.我正在开发 Quarkus RestEasy JAX-RS 端点。 I want to use a Multi-Tenant Architecture (not separate database or separate schema but shared database with discriminator column like tenantId).我想使用多租户体系结构(不是单独的数据库或单独的模式,而是具有像tenantId 这样的鉴别器列的共享数据库)。 Quarkus also only support separate database and separate schema like Hibernate. Quarkus 也只支持单独的数据库和单独的模式,如 Hibernate。

So, how can I implement a custom resolver to write my endpoint resources methods (get, post, put, delete) according to a tenantId?那么,如何实现自定义解析器来根据tenantId 编写我的端点资源方法(get、post、put、delete)?

I thought about an interceptor or filter, but I have no idea how to implement it with Quarkus.我想过一个拦截器或过滤器,但我不知道如何用 Quarkus 实现它。

The idea is (SaaS):这个想法是(SaaS):

  • Create customer account (set him a tenant ID)创建客户帐户(为他设置租户 ID)
  • When a user login, data are fetched according to his tenantId.当用户登录时,根据他的tenantId获取数据。

The use case:用例:

Tenant1 sends HTTP request containing his tenantId, from endpoint resources, get the tenantId and implement save(), getAll(), get(), delete() methods according to the current tenantId value, and so every tenant will only get or add his own data. Tenant1 发送包含他的tenantId 的HTTP 请求,从端点资源中获取tenantId 并根据当前tenantId 值执行save()、getAll()、get()、delete() 方法,因此每个租户只会获取或添加他的自己的数据。

Other possibility:其他可能性:

Is it possible to use a separate schema and write a service (manager dashboard) which can pickup data from all tenants schemas?是否可以使用单独的模式并编写一个可以从所有租户模式中获取数据的服务(管理仪表板)?

Example:例子:

  • Tenant1 = StackOverflow US (number of employees = 50) (employee table in SCHEMA 1) Tenant1 = StackOverflow US(员工人数 = 50)(SCHEMA 1 中的员工表)

  • Tenant2 = StackOverflow France (number of employees = 30) (employee table in SCHEMA 2) Tenant2 = StackOverflow France(员工人数 = 30)(SCHEMA 2 中的员工表)

  • StackOverFlow Global Manager Dashboard (Total employees = 80, sum of Schema 1 employee table and Schema 2 employee table ) and he can also have statistics by subsidiary. StackOverFlow 全球经理仪表板(员工总数 = 80,架构 1 员工表架构 2 员工表的总和),他还可以按子公司进行统计。

Quarkus currently only support separate database and separate schema for multi-tenancy, see https://quarkus.io/guides/hibernate-orm#multitenancy Quarkus 目前仅支持多租户的单独数据库和单独模式,请参阅https://quarkus.io/guides/hibernate-orm#multitenancy

What you want is Partitioned (discriminator) data, see https://docs.jboss.org/hibernate/orm/4.3/devguide/en-US/html/ch16.html#d5e4808您想要的是分区(鉴别器)数据,请参阅https://docs.jboss.org/hibernate/orm/4.3/devguide/en-US/html/ch16.html#d5e4808

So, if you can use separate schema, it's doable OOTB with Quarkus.因此,如果您可以使用单独的模式,那么使用 Quarkus 进行 OOTB 是可行的。

For your global dashboard, you can for example create a view on a dedicated schema that is the union of the corresponding table on "by tenant" schema.例如,对于您的全局仪表板,您可以在专用模式上创建一个视图,该模式是“按租户”模式上相应表的联合。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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