简体   繁体   English

如何在每个数据库具有不同架构的每个租户应用程序中处理具有数据库的多租户

[英]How to handle a multi tenant with database per tenant application where each database has a different schema

I have a situation where I'm currently building a multitenant application where each tenant has its own database.我目前正在构建一个多租户应用程序,其中每个租户都有自己的数据库。 The problem that I'm struggling with is that each database could have a vastly different structure.我正在努力解决的问题是每个数据库都可能具有截然不同的结构。 There are approximately 150 different tenants with each database being different.大约有 150 个不同的租户,每个数据库都不同。 Is there a method of being able to cleanly manage this?有没有办法能够干净地管理这个?

I'm aware of how to handle a single application with multiple databases but I'm lost on how I can implement this over several different schemas without the code base becoming unmaintainable.我知道如何处理具有多个数据库的单个应用程序,但我不知道如何在几个不同的模式上实现它而不会使代码库变得不可维护。 An initial idea would be separating the data layer so each tenant has it's own repositories and entities as an individual micro service.最初的想法是分离数据层,以便每个租户都有自己的存储库和实体作为单独的微服务。 This isn't really scalable long term but would provide the separation of keeping the core logic separated from the individual databases but feels a bit hacky.从长远来看,这并不是真正的可扩展性,但会提供将核心逻辑与单个数据库分开的分离,但感觉有点笨拙。 Are there any patterns, advice or examples where I could be pointed to so I can read further on this?是否有任何模式、建议或示例可以指向我,以便我可以进一步阅读? Or is the method going forward just completely unfeasible?还是这种方法完全不可行?

I'm not asking anybody to write code for me or to provide a solution.我不是要求任何人为我编写代码或提供解决方案。 I would just like a bit of advice for someone who may have worked with this kind of situation and potentially recommend steps forward.我只是想给那些可能在这种情况下工作过并可能建议向前迈出一步的人一些建议。

I think creating a common data layer is your best bet.我认为创建一个通用数据层是你最好的选择。 You absolutely don't have a scalable solution because you don't have a scalable problem.您绝对没有可扩展的解决方案,因为您没有可扩展的问题。 Hopefully they have enough in common that you can have a common mapping layer with plugins/overrides for particular entities that differ from that common core.希望它们有足够的共同点,您可以拥有一个通用映射层,其中包含与该通用核心不同的特定实体的插件/覆盖。

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

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