Skip to content

Latest commit

 

History

History
64 lines (45 loc) · 2.47 KB

File metadata and controls

64 lines (45 loc) · 2.47 KB

Supabase PostgreSQL Setup for Vercel

Database Connection String

IMPORTANT: For Vercel serverless functions, you MUST use the Transaction Pooler (port 6543) to avoid connection limit errors.

Use the PRISMA/Transaction Pooler URL (port 6543 with pgbouncer=true):

postgres://postgres.rxbitapqomwllggjyrvk:KS3xayqmT8OKISxD@aws-1-us-east-1.pooler.supabase.com:6543/postgres?sslmode=require&pgbouncer=true

Why? Vercel serverless functions create many concurrent instances. The transaction pooler handles this much better than direct connections.

Setting Up in Vercel

  1. Go to your Vercel project dashboard

  2. Add the Database URL Environment Variable:

    • Key: DATABASE_URL (or stridelens_POSTGRES_PRISMA_URL)
    • Value: postgres://postgres.rxbitapqomwllggjyrvk:KS3xayqmT8OKISxD@aws-1-us-east-1.pooler.supabase.com:6543/postgres?sslmode=require&pgbouncer=true
    • Environments: Select all (Production, Preview, Development)
    • Click Save
  3. Alternatively, use the prefixed variable:

    • Key: stridelens_POSTGRES_PRISMA_URL
    • Value: postgres://postgres.rxbitapqomwllggjyrvk:KS3xayqmT8OKISxD@aws-1-us-east-1.pooler.supabase.com:6543/postgres?sslmode=require&pgbouncer=true
  4. Redeploy your application - migrations will run automatically!

What Happens Next

Once the DATABASE_URL is set:

  • ✅ Django will automatically connect to Supabase PostgreSQL
  • ✅ Migrations will run automatically on first request
  • ✅ All data will persist across deployments and devices
  • ✅ Users can log in from any device and see their saved routes

Testing Locally

To test with Supabase locally, create a .env file in your project root:

For local development, you can use the non-pooling URL (port 5432):

DATABASE_URL=postgres://postgres.rxbitapqomwllggjyrvk:KS3xayqmT8OKISxD@aws-1-us-east-1.pooler.supabase.com:5432/postgres?sslmode=require

For production/Vercel, use the transaction pooler (port 6543):

DATABASE_URL=postgres://postgres.rxbitapqomwllggjyrvk:KS3xayqmT8OKISxD@aws-1-us-east-1.pooler.supabase.com:6543/postgres?sslmode=require&pgbouncer=true

Then run migrations:

python manage.py migrate

Security Note

These credentials are sensitive. Make sure:

  • ✅ Never commit .env files to git
  • ✅ Use environment variables in Vercel (not hardcoded)
  • ✅ Rotate credentials if they're exposed