Supabase Setup Guide
Overview
This guide covers the complete Supabase setup for the Remind Tools monorepo, including database schema, Row Level Security policies, and Flutter integration.Table of Contents
- Local Development Setup
- Database Schema
- Environment Configuration
- Flutter Integration
- Running Migrations
- Testing
Local Development Setup
Prerequisites
- Node.js 18+ installed
- Docker Desktop running
- Flutter SDK installed
Install Supabase CLI
Initialize Local Supabase
Database Schema
The database schema is organized into versioned migrations in/supabase/migrations/
:
Core Tables
- profiles - User profiles extending Supabase auth
- trips - User trips with AI suggestions
- places - Points of interest with PostGIS support
- itineraries - Daily planning for trips
- trip_collaborators - Trip sharing functionality
- audit_log - Data change tracking
Key Features
- PostGIS extension for geospatial queries
- Row Level Security (RLS) for multi-tenant isolation
- Full-text search indexes on trips and places
- Materialized views for performance optimization
- Automatic profile creation on user signup
Environment Configuration
1. Create Environment File
Copy the example file and fill in your credentials:2. Edit .env.development
3. Verify .gitignore
Ensure environment files are not committed:Flutter Integration
1. Bootstrap Workspace
2. Initialize Supabase in Your App
The Supabase client is configured in/packages/core/lib/infrastructure/database/supabase_client.dart
In your main app file:
3. Using the Supabase Client
Running Migrations
Apply All Migrations
Create New Migration
Push to Remote
Testing
1. Test RLS Policies
2. Test Helper Functions
3. Integration Tests
Create test files in/test/
directories:
Domain Entities
The domain entities are defined in/packages/data_models/lib/src/trips/entities/
:
- Profile - User profile with preferences
- Trip - Trip with status tracking and budget
- Place - Points of interest with location data
- Itinerary - Daily activities and planning
- Immutable properties with Equatable
- Convenient helper methods
- CopyWith pattern for updates
- Validation logic
Security Best Practices
- Never commit credentials - Use environment files
- Use RLS policies - All tables have Row Level Security enabled
- Validate input - Use domain entities with validation
- Audit changes - audit_log table tracks important changes
- Use service role carefully - Only for admin operations
Troubleshooting
Common Issues
-
Supabase not starting
- Ensure Docker Desktop is running
- Check port conflicts (54321, 54322, 54323)
- Run
supabase stop
thensupabase start
-
Migration errors
- Check SQL syntax in migration files
- Ensure proper order of migrations
- Review PostgreSQL logs:
supabase db logs
-
Authentication issues
- Verify environment variables are loaded
- Check Supabase auth settings
- Ensure RLS policies are correct
-
Flutter connection issues
- Verify SUPABASE_URL and SUPABASE_ANON_KEY
- Check network connectivity
- Review Flutter console logs
Next Steps
- Implement repository pattern - Create repository interfaces in domain layer
- Add data sources - Implement remote and local data sources
- Create use cases - Business logic for trip management
- Build UI - Create Flutter widgets using BLoC pattern
- Add tests - Unit, widget, and integration tests