Development and Production Workflow

I know you use Supabase so I am very thankful for your input. My experience with databases is limited and know from other projects in Rails that there is a better way. This might be long and a little convoluted but I’ll do my best…

Specifically, I’m looking for how to set up the .env file the best. I have things running several ways locally on different repos. For the one that I am running Supabase…I’ve gone about it in two ways with some success.

  1. Run Supabase locally with a shadow database. This spins up Docker and I can Prisma migrate locally fine.
//.env  

// This is the port I spun the Docker up on
DATABASE_URL=postgres://postgres:postgres@localhost:5432/postgres

// Local Supabase after supabase init and supabase start
SUPABASE_URL=http://localhost:8912
SUPABASE_KEY=[given in the terminal on spinup]
SUPABASE_JWT_SECRET=[given in the terminal on spinup]
SHADOW_DATABASE_URL=[Based on spinup]

// Another set of connections for Supabase in "the cloud" right now for production only
# DATABASE_URL=postgresql://postgres:[supaandpass].supabase.co:5432/postgres <-- I assume this is bad
# SUPABASE_URL=https://[generatedbysupa].supabase.co
# SUPABASE_KEY=[from Supabase settings]
# SUPABASE_JWT_SECRET=[from Supabase settings]

This approach worked except when running auth. I don’t believe Supabase is supporting the local dev environment for auth and to be honest I didn’t even try. I would just comment in and out the local vs. “cloud” when pushing changes to production.

  1. The second method was to set up Supabase Auth and run a local Postgres instance in Docker.
//.env

// Based on docker-compose.yml
DATABASE_URL=postgresql://postgres:postgres@localhost:5432/postgres
TEST_DATABASE_URL=postgresql://postgres:postgres@localhost:5438/postgres

// Supabase Cloud - comment out Database here
# DATABASE_URL=postgresql://postgres:[supaandpass].supabase.co:5432/postgres
SUPABASE_URL=https://[generatedbysupa].supabase.co
SUPABASE_KEY=[from Supabase settings]
SUPABASE_JWT_SECRET=[from Supabase settings]

As I move closer to production, I know things need to be set up more sustainably and securely. I haven’t even got to the wonderful solution that you posted nor appended the connections with ?connection_limit=1.

I also made it successfully through the tutorial a few times and deployed it to Netlify. I used Railway but also struggled with the next steps on how to make a clean production, development, and testing environment.

I know each setup is going to vary but am looking for a general config that works for many if that makes sense. Again thank you!