Dynamic Database Name Support in Studio

I’m facing a recurring issue during development that forces me to duplicate projects just to manage different .env files. Let me explain the scenario: Currently, I’m working on a project with a MASTER database that handles tenant access and several TENANT_###### databases, each specific to a client. Here’s the workflow: 1 - I connect to the URL (example): localhost:5432/MASTER to access the master database. 2 - I find the client’s number (e.g., 50). 3 - Then, I have to close Studio, switch the .env file from MASTER to TENANT_000050, and reopen Studio. This process complicates development significantly. To keep things running smoothly, I currently duplicate the project just so both the MASTER and one TENANT can stay online simultaneously, which is far from ideal. Suggestion: Would it be possible to create a script or feature that allows passing dynamic arguments, like -d TENANT_000050, when starting Studio? Note: I’m considering making a fork or opening a PR to implement this directly in the Studio interface. I think having an input field to dynamically change the database name via the browser would be a fantastic productivity booster. What do you think? Is there any existing solution or idea for this?
1 Reply
RaphaelEtim
RaphaelEtim2mo ago
Hi @Israel Santos Currently, Prisma doesn't have a built-in feature to dynamically switch databases within Studio as you've described. One workaround is to use environment variable to dynamically set the database URL using dotenv-cli. For example: 1. You will create an env file .env.TENANT_000050. In this file, you will add the database URL for that tenant. 2. You will create another env file .env.master. In this file, you will add the database URL for that master. 3. Install dotenv-cli Then you can issue the command below to start studio for the tenant.
dotenv -e .env.TENANT_000050 -- npx prisma studio
dotenv -e .env.TENANT_000050 -- npx prisma studio
Note: I’m considering making a fork or opening a PR to implement this directly in the Studio interface. I think having an input field to dynamically change the database name via the browser would be a fantastic productivity booster.
Prisma Studio is free software but not OSS so you won't be able to fork it as the repo is private. You can however submit a feature request and document your usecase so that our engineering team can take a look.
Want results from more Discord servers?
Add your server