I am implementing a multi-tenant application using a "Database-per-tenant" strategy with a shared application layer. I have two specific questions regarding the connection workflow:
Connection Switching: Since I cannot store every tenant's credentials in a .env file or redeploy for new clients, what is the best practice for resolving connections at runtime? I am looking for a pattern to manage a dynamic connection pool based on the Tenant ID of each request.
Master Database Security: I assume a "Master DB" is required to store the metadata and credentials for all tenant databases. Should the credentials for this Master DB be the only ones stored in the environment variables?