-
Notifications
You must be signed in to change notification settings - Fork 88
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
Transactions does not work with multi tenant application #93
Comments
Thanks! See https://github.com/odavid/typeorm-transactional-cls-hooked#using-transactional-decorator Hope it helps... |
Thanks @odavid for your reply. Unfortunately I have no idea how to get the connection name within the decorator, since I have no access to the request in that context (I think), The connection name is the tenant name that I retrieve from the JWT in the Authorization header. Any idea? Could you please provide an example or direct me to a sample? Thanks in advance. |
I don't think this is related to multi tenant. I am using nestjs and it doesn't work as well. |
Hello, I am stuck in this same situation. Some help? |
I'm using multi tenant too just as op said, |
I can't get everything to run within the same transaction. I have the following code:
The following is executed in the database:
As you can see, 2 transactions are executed, I need it to be only one |
it's working for me now
|
@mohsinamjad |
@pavel-xendit my package info "typeorm": "0.2.34", |
@mohsinamjad |
@odavid @mohsinamjad |
it is possible to use async-hooks or cls-hooked or some other similar package for creating request scoped context. |
For multi tenant your connection name will be dynamic like in my case I set tenant ID as connection name, and you can't use same connection name is e.g default. |
I believe that there is no definitive solution to this problem. In my case, I used middleware to initialize the database connection and store it in a global variable so the user can re-use it, but that caused the transactional issue since So I came out with a solution to sync all tenant data to a JSON file (only the scheme name) and read the file data on app init so I can register all schemes with Some sample
Just imagine this part The downside is that I have to restart the app every time a new tenant arrives, and hope someone jumps in and gives a pro solution. |
First of all, thank you for this library. It's a must-have.
I am using nest.js to create a multi tenant application, so the module creates the connection dynamically and injects into the service, and then I get the repository like this:
The
main.ts
is:Although my application works fine, transactions just don't work. Am I missing something?
The text was updated successfully, but these errors were encountered: