Source:
ocean/docs/LOCAL_TESTING_README.md| ✏️ Edit on GitHub
Local Testing Environment
This directory contains documentation and guides for setting up and using the local Supabase testing environment.
Overview
While we follow a cloud-first testing strategy (ADR-014), we maintain a local testing environment for specific use cases:
- Database Development: Trigger and function development
- Migration Testing: Safe schema change testing
- Bug Reproduction: Debugging production issues locally
- RLS Policy Testing: Testing Row Level Security policies
Quick Start
# 1. Ensure Docker is running
docker ps
# 2. Start local Supabase
supabase start
# 3. Apply migrations
supabase db reset --no-seed
# 4. Run debug scripts
pnpm debug:user "test@example.com" "Test Org"
Documentation
Setup & Configuration
- LOCAL_TESTING_SETUP.md - Comprehensive setup guide
- ADR-028 - Architecture decision for local testing
Debug Scripts
/scripts/debug-user-creation.js- Interactive user creation debugger/scripts/debug-user-creation.sql- SQL queries for troubleshooting/scripts/test-local-user-creation.js- Automated test scenarios
Environment Configuration
.env.local.test- Local environment variables (do not commit)supabase/config.toml- Local Supabase configuration
Common Tasks
Debug a Production Issue
- Get error details from production logs
- Start local environment
- Reproduce issue with debug scripts
- Fix and test locally
- Deploy fix to production
Test a Migration
- Create migration file
- Apply to local database
- Test functionality
- Test rollback scenario
- Apply to cloud environments
Verify RLS Policies
- Create test users with different roles
- Test data access patterns
- Verify security boundaries
- Document expected behavior
Best Practices
- Always test in cloud before deploying
- Reset database between test sessions
- Document findings in debug scripts
- Keep local in sync with production schema
Troubleshooting
Common Issues
- Port conflicts: Stop other services using ports 54321-54324
- Migration errors: Check for duplicate timestamps
- Auth errors: Ensure using correct service keys
- Connection refused: Check Docker containers are running
Getting Help
- Check the LOCAL_TESTING_SETUP.md guide
- Review Supabase CLI docs
- Ask in team Slack channel
- Check Docker logs:
docker logs supabase_db_ocean