I hope you can help enlighten me.
Here’s the problem I’m facing:
I have a Spring Boot project (version 3.1.4). The database is really old (DB2).
This is its structure:
- SCHEMA_COMMON :
- COMMON_TABLE_A
- COMMON_TABLE_B
- …
- SCHEMA_A_1 :
- TABLE_A_1
- TABLE_A_2
- TABLE_A_3
- …
- SCHEMA_B_1 :
- TABLE_B_1
- TABLE_B_2
- TABLE_B_3
- …
- SCHEMA_A_9 :
- TABLE_A_1
- TABLE_A_2
- TABLE_A_3
- …
- SCHEMA_B_9 :
- TABLE_B_1
- TABLE_B_2
- TABLE_B_3
- …
Although this is theoretical, it gives an idea of the database structure I have to work with. The tables in SCHEMA_A are all the same (as are those in SCHEMA_B). We use this approach to separate data.
I have already implemented MultiTenancy, but with this setup, I have to set each tenant before each database request.
So here is my question about Spring Boot:
I would like to specify the correct datasource based on a property in my token. I already have the idea in mind, but I can’t develop it further. For example, let’s say USER_1 makes a GET request to my controller. Because he has TENANT_1 in his token, he will have access to all schemas (and therefore tables) that end with 1. USER_9, who has TENANT_9, will have access to all schemas that end with 9. In the future, we might add USER_10, and so on.
I really hope my explanation is clear despite its complexity.
Thanks in advance 🙂