How to protect database credentials?

Not really, you can just set environment variables in your prod environment.