Finbuckle / Finbuckle.MultiTenant

Finbuckle.MultiTenant is an open-source multitenancy middleware library for .NET. It enables tenant resolution, per-tenant app behavior, and per-tenant data isolation.
https://www.finbuckle.com/multitenant
Apache License 2.0
1.33k stars 266 forks source link

Multitenant based on database schema #378

Open endrihacker opened 3 years ago

endrihacker commented 3 years ago

Hello again @AndrewTriesToCode,

I'm currently using multitenancy with separate database per tenant. In PostgreSql there is a low limit of database connection per database instance (around 100 by default, and can't be increased to the range of some thousands). I know that I can use single database multitenancy, or even hybrid approach. But what I want to do is to keep the data completely separate between tenants.

If I don't find a suitable way to manage database connections not to reach the limit I think I will give a try to database schema. I saw that schema can be changed programmatically from this StackOverflow question.

I don't see it in the docs of this library. Do you have any plan to add it in the future?

AndrewTriesToCode commented 3 years ago

Hi @endrihacker I've used separate schema for each tenant on small test apps but it was done by manipulating the connection string with MS Sql Server. I'll keep this as a feature request but I'm not sure how feasible it would be.

mguinness commented 3 years ago

There is an existing open issue https://github.com/dotnet/efcore/issues/9965 that you could upvote. A couple of other ideas - could you execute set schema 'xyz'; with Interception of database operations or use the new feature Connection or connection string can be changed on initialized DbContext in .NET 5 and change search path?