3.8 KiB
Local Supabase Setup Guide
This guide will help you set up and run Supabase locally for development.
Prerequisites
-
Docker Desktop - Supabase runs on Docker
- Download: https://docs.docker.com/desktop
- Make sure Docker Desktop is running before proceeding
-
Supabase CLI - Already installed via Homebrew
Quick Start
1. Start Local Supabase
cd old
./scripts/setup-local-supabase.sh
This script will:
- Check if Docker is running
- Initialize Supabase (if not already done)
- Start all Supabase services locally
- Apply all database migrations
- Display your local credentials
2. Run Flutter App with Local Supabase
./scripts/run-flutter-local.sh
Or specify a device:
./scripts/run-flutter-local.sh chrome
./scripts/run-flutter-local.sh web-server
3. Get Credentials Manually
If you need to see the credentials again:
./scripts/get-local-credentials.sh
Or use the Supabase CLI directly:
supabase status
Manual Setup
If you prefer to set up manually:
Step 1: Start Supabase
cd old
supabase start
Step 2: Get Credentials
After starting, supabase status will show:
- API URL: Your local Supabase URL (usually
http://127.0.0.1:54321) - anon key: Your local anon key
Step 3: Run Flutter with Credentials
flutter run -d chrome \
--dart-define=SUPABASE_URL="http://127.0.0.1:54321" \
--dart-define=SUPABASE_ANON_KEY="<your-anon-key>"
Useful Commands
Supabase Management
# Start Supabase
supabase start
# Stop Supabase
supabase stop
# View Supabase status and credentials
supabase status
# View logs
supabase logs
# Reset database (applies all migrations fresh)
supabase db reset
# Apply new migrations
supabase db reset
Database Migrations
Migrations are automatically applied when you run supabase start or supabase db reset.
To create a new migration:
supabase migration new <migration_name>
Local Supabase Services
When running locally, Supabase provides:
- API:
http://127.0.0.1:54321 - Studio (Admin UI):
http://127.0.0.1:54323 - Database:
postgresql://postgres:postgres@127.0.0.1:54322/postgres - Auth: Handled by the API
- Storage: Handled by the API
Accessing Supabase Studio
Supabase Studio is a web-based admin interface for managing your local database:
- Start Supabase:
supabase start - Open Studio URL from
supabase statusoutput (usuallyhttp://127.0.0.1:54323) - Use it to:
- View and edit tables
- Run SQL queries
- Manage authentication
- View API documentation
Troubleshooting
Docker Not Running
Error: Cannot connect to the Docker daemon
Solution: Start Docker Desktop and wait for it to fully start, then try again.
Port Already in Use
If ports 54321, 54322, or 54323 are already in use:
- Stop the conflicting service
- Or modify
supabase/config.tomlto use different ports
Database Reset Issues
If migrations fail:
# Stop Supabase
supabase stop
# Reset everything
supabase db reset
# Start again
supabase start
Flutter Can't Connect
Make sure:
- Supabase is running (
supabase status) - You're using the correct URL and anon key
- The
--dart-defineflags are correctly formatted
Switching Between Local and Production
Use Local Supabase
./scripts/run-flutter-local.sh
Use Production Supabase
Update env.json with production credentials and run:
flutter run -d chrome \
--dart-define-from-file=env.json
Note: The current app uses String.fromEnvironment, so you need --dart-define flags.
Next Steps
- ✅ Start Docker Desktop
- ✅ Run
./scripts/setup-local-supabase.sh - ✅ Run
./scripts/run-flutter-local.sh - ✅ Open Supabase Studio to view your database
- ✅ Start developing!