Skip to content

Latest commit

 

History

History
81 lines (57 loc) · 2.53 KB

File metadata and controls

81 lines (57 loc) · 2.53 KB

Database Setup Guide

Important: Complete Your .env Configuration

Before running the application, you need to update the .env file with your actual Supabase credentials:

  1. Replace [YOUR-PASSWORD] in the DATABASE_URL with your actual database password from Supabase
  2. Add your Supabase API keys:
    • SUPABASE_ANON_KEY: Your project's anonymous key
    • SUPABASE_SERVICE_KEY: Your project's service role key

Connection Types

The .env file includes three connection options:

  1. Direct Connection (default): Best for persistent connections

    DATABASE_URL=postgresql://postgres:[YOUR-PASSWORD]@db.nmriopbblradducblaoc.supabase.co:5432/postgres
    
  2. Transaction Pooler: Best for serverless functions

    DATABASE_URL=postgres://postgres:[YOUR-PASSWORD]@db.nmriopbblradducblaoc.supabase.co:6543/postgres
    
  3. Session Pooler: For IPv4 networks

    DATABASE_URL=postgres://postgres.nmriopbblradducblaoc:[YOUR-PASSWORD]@aws-0-us-east-2.pooler.supabase.com:5432/postgres
    

Testing the Connection

  1. Make sure your .env file is configured with the correct credentials
  2. Run the server:
    go run ./cmd/server
  3. Test the database connection:
    curl http://localhost:8080/debug/db

About the Email Validation Error

The error you're experiencing with "email_address_invalid" is likely due to Supabase Auth configuration. By default, Supabase might be configured to:

  1. Block certain email domains (like example.com)
  2. Require email confirmation

To fix this:

  1. Go to your Supabase Dashboard → Authentication → Settings
  2. Check if "Email Confirmations" is enabled
  3. Check if there are any email domain restrictions
  4. You can also disable email confirmations for testing:
    • Go to Authentication → Providers → Email
    • Toggle off "Confirm email"

Alternatively, use a real email address instead of demo@example.com for testing.

Database Client Usage

The database client is now available in your handlers through sb.Database. Example usage:

// Execute a query
rows, err := sb.Database.ExecuteQuery(ctx, "SELECT * FROM users WHERE email = $1", email)

// Execute a single row query
var userID string
err := sb.Database.ExecuteQueryRow(ctx, "SELECT id FROM users WHERE email = $1", email).Scan(&userID)

Security Notes

  • Never commit your .env file (it's already in .gitignore)
  • Keep your service role key secret
  • Use environment variables in production
  • Remove the /debug/db endpoint before deploying to production