I have read several posts/topics (like this, this and this) about the subject SaaS, Multi-Tenant, etc. and I reached the conclusion that most of them does not fit my requirements:
- I don't need a multi-tenant as i'm only going to use the main-domain
- I can't write in .env nor in database.config all my MySQL connections as they will all be dynamic (at least the name of the database)
Workflow i need:
- The subscriptions (SaaS) contains the database name
- Whenever the user login it is assigned to his session the database name
- Run all the queries to the user database
Example:
- project_admin <- Main database
--- subscriptions <- Table
------ id | db_name
------ 1 | project_child_one
------ 2 | project_child_two
--- users <- Table
------ id | subscription_id
------ 1 | 1
------ 2 | 2
- project_child_one <- Child database
--- customers <- table
- project_child_two <- Child database
--- customers <- table
- When the
user 1
login, the data retrieved from customers should be from databaseproject_child_one
. - When the
user 2
login, the data retrieved from customers should be from databaseproject_child_two
.
I want the database name to be saved in the session so I don't need to always query the project_admin
in order to know in which database the user should connect to. This is the easy part.