-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add example for Multi-Tenant #9
Comments
So you would have a list of defined tenants in the config somewhere, available to the middleware?
Not sure what you mean by "preload all entities". You can pass a list of entities to analyse/discover. All entities you want to use need to be discovered (and they all need to be valid, e.g. if you have Book entity that is referring to Author entity, you need to discover both).
Forking/request context helper are needed, that is not just about multi tenancy, you need to have a clear context (fork) for each request. I never used it this way (never worked with a tenant per db app), so its hard to give you advice on how to do it the right way :] But what they do in objection should be possible, you can augment the With a tenant per schema (all in one db) you could use single ORM instance I guess. |
@B4nan I was just looking into this for a future project. I've done multi-tenant in the past using a Document Store... it was fairly easy to implement.
This is probably not the best option given the overhead of 1000 tenents I imagine. I think the best approach is to be able to tell the ORM which database to point to on a given request. Any ideas if that's doable? |
Is your feature request related to a problem? Please describe.
Using multiple connections and binding connections to entities.
Describe the solution you'd like
For example:
A request is sent to an API and a middleware would introspect and select which tenant database connection.
I see that the
.init
the function would preload all the entities. Would that cause any problem to somehow load the entities on-demand based on different database connections?Ex:
GET /foo (123)
I've found in the docs that it's possible to solve that by using
const em = orm.em.fork();
orFor ref, I think having something like https://vincit.github.io/objection.js/recipes/multitenancy-using-multiple-databases.html in the docs would be very beneficial.
The text was updated successfully, but these errors were encountered: