It would be interesting the possibility of creating datasources single or multiple tenants on the same database, this way would be possible to situations such as:
In the case of postgresql you can define a schema is a tenant, but in the case of mysql has to be a bank for tenant. Therefore, this functionality would affect the existing connectors.
The operating result could be similar to the GEM Apartment Rails.
https://github.com/influitive/apartment
Another nice example is the Oracle 12c - http://www.oracle.com/technetwork/database/multitenant/overview/index.html
Or App Engine Java for Google Cloud - https://cloud.google.com/appengine/docs/java/multitenancy/?csw=1
Node 6.9.1
Strongloop 6.0.3 / Api Connect 2.3.10
Strong-PM 5.2.3
There is some WIP that has been delayed for awhile at https://github.com/strongloop/loopback-multitenancy
I read that also has another POC project here in strongloop - https://github.com/strongloop/loopback-multitenant-poc which deals with the same subject. I'll see them, but would like an official version :-)
@superkhau I thank you very much for the tip and I will study it for sure.
Some articles I found very interesting about it are these:
For those who are new like me on the subject, but need this functionality, read on:
Some friends have told me can do multi-tenant on loopback (as in the examples cited above and @superkhau contribution) but always lose something, be the explorer, such as integration with the ARC or other great features of this loopback environment.
As already mentioned before, I am new to Node, Express, Loopback, but I want to learn from this process and maybe one day to contribute to the community that is very active in this project.
I would like to know the opinion of @ritch, @tj, @ry, @bnoordhuis, @isaacs, @seanbrookes, @anthonyettinger, @raymondfeng, @1602 and @bajtos on the subject, as they are also closely linked with projects like strongloop, loopback, express and node. In addition to the expertise they have in this ecosystem.
Searching the Internet for that feature, I saw some posts that recommended the use of several Docker containers, one for each tenant. Personally, I don't believe that's manageable, and walks away from the concept of multitenancy. The multitenancy feature on StrongLoop would be a great addition to the project.
Best regards!
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Thought I'd add my two cents here so I can share the strategy that has been successful for us:
For any model that should be seen only from one organization's perspective, we have a mixin that hooks everything.
The before save is the hairy part of it, and required a lot of checks to be set up before I was confident that a user couldn't do anything outside of their org.
We also do some role checking, where a super user just calls next() right away, etc.
I'm ambivalent about the quality of this solution, but it does work and the performance implications aren't terrible. The security implications are probably fairly severe however, and I wouldn't trust it in the wild without some serious engineering.
@joincamp -- we're interested in a similar solution. Could you share a gist of the relevant code for illustration?
@drmikecrowe Can we talk outside of here? I wouldn't consider my solution "community-ready", so I'd prefer to share in private.
@joincamp Got it, thanks many
@joincamp I'd be really interested to take a look at your implementation too
I created a POC with tenant with multiple users, each tenant with it's users per database. I ran a test with 10 tenants, each with one user, each user created one new Note model instance. Loopback(node in general) seems to prioritize queuing requests over handling them as it's non locking, and I think this is the main problem when dynamically switching data source with attachTo. Resulting Note model instances were all over the place. I assume they were saved in the currently active datasource on Note model and the correct datasource where the Note should've been saved is long gone when the request is actually being handled.
I'm still looking for a feasable solution, is it possible to setup loopback to handle per request datasource? Maybe a custom connector with connection options when executing a query?
If anyone is interested, it's possible to create multitenancy using schemas in postgres that does not fail concurrency tests. I check for access token on each request and fetch tenants schema name from a single master DB. When I have the schema name it's attached to ctx.options and ctx.args, in this way I can read options.schema in execute function in sql connector and switch "public" schema in sql statement with it.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
This issue has been closed due to continued inactivity. Thank you for your understanding. If you believe this to be in error, please contact one of the code owners, listed in the CODEOWNERS file at the top-level of this repository.
@joincamp Can you send me your code about this issue ?
@hoangtrongphuc Sure, I invited you to my repo.
I'm not get any notify about your repo, you can send me : dr.[email protected]
This script allow multitenant (postgre schema based).
http://subdomain.domain.com => set subdomain schema in every model. Need edit model-config.json to add "tenant": true
{
...
"MyModel": {
"dataSource": "db",
"public": true,
"tenant": true
},
...
}
https://gist.github.com/paulomcnally/0fea84f0c5ed7fce70fd26d134c65c5f
@joincamp, does the offer to share your concept still hold? Would be interested to see what you came up with vs. what we bolted together here.
Most helpful comment
Searching the Internet for that feature, I saw some posts that recommended the use of several Docker containers, one for each tenant. Personally, I don't believe that's manageable, and walks away from the concept of multitenancy. The multitenancy feature on StrongLoop would be a great addition to the project.
Best regards!