Most likely not in this case, you would likely need to use the bootstrap function to set the variables at the initial boot as before the application starts there is migration level that happens that checks the database.
I would have to do some testing, you might be able to perform some logic outside the exports object of the database.js file however I’m not sure if that will throw errors on boot since I believe it’s designed to pull from environment variables.
The alternative would be to have a custom start script that pulls the environment variables and sets them before Strapi even starts like a typical node server.js file