Open nhalase opened 2 years ago
This looks a good approach to me. Another option could be having separate Database
instance for all the tenant databases, but that would make connection pooling trickier and probably it would waste a lot of resources.
First approach looks more robust because it delegates the database specific switch to the framework, so if you switch from Postgres, you probably don't have to rewrite this part.
We are having the same thing right now.
Actually, in order to make it work, we have to put the schema name in double quotes, so the resulting sql is
SET search_path TO "CUSTOMER123"
Here the Exposed Code:
transaction {
SchemaUtils.setSchema(schema = Schema("\"$clientId\""))
// whatever query here
}
I do not like this solution. Also i am not sure about security here.
I'm looking for advice on a good way to handle schema-based multi-tenancy with Exposed. I'm getting tripped up because of Ktor and Coroutines and I'm coming from a Spring background where I would normally just use
MultiTenantConnectionProvider
from Hibernate.Context:
Here is my current solution:
Theoretically, this could work, too:
Questions:
Thanks!