Supabase Setup Guide¶
This guide walks you through setting up Supabase for the Juddges App, including database initialization, authentication configuration, and verification.
Table of Contents¶
Prerequisites¶
Before starting, ensure you have:
- Supabase Account: Sign up at supabase.com
- Supabase CLI: Install via
npm install -g supabaseor other methods - Node.js 18+: For frontend development
- Python 3.12+: For backend development
- Poetry: For Python dependency management
Quick Start¶
1. Create a Supabase Project¶
- Go to Supabase Dashboard
- Click "New Project"
- Fill in project details:
- Name:
juddges-app(or your preferred name) - Database Password: Generate a strong password
- Region: Choose closest to your users
- Wait for project initialization (~2 minutes)
2. Get Your Credentials¶
Once your project is ready:
- Go to Settings → API
- Copy the following values:
- Project URL (e.g.,
https://xxxx.supabase.co) - Anon/Public Key (safe for frontend)
- Service Role Key (⚠️ secret, backend only)
3. Configure Environment Variables¶
Copy .env.example to .env and fill in your Supabase credentials:
Edit .env:
# Supabase Configuration
SUPABASE_URL=https://your-project-ref.supabase.co
SUPABASE_ANON_KEY=your-anon-key-here
SUPABASE_SERVICE_ROLE_KEY=your-service-role-key-here
# Frontend (auto-populated from above)
NEXT_PUBLIC_SUPABASE_URL=${SUPABASE_URL}
NEXT_PUBLIC_SUPABASE_ANON_KEY=${SUPABASE_ANON_KEY}
# OpenAI (required for embeddings)
OPENAI_API_KEY=sk-your-openai-api-key-here
4. Link to Remote Project¶
Link your local Supabase CLI to your remote project:
You can find your project-ref in the Supabase Dashboard URL or under Settings → General.
5. Apply Migrations¶
Push all migrations to your remote database:
This will create:
- ✅ judgments table with vector search
- ✅ profiles table for user metadata
- ✅ Row Level Security (RLS) policies
- ✅ Search functions (semantic + full-text)
- ✅ Auth schema verification
6. Verify Setup¶
Run the verification script to ensure everything is configured correctly:
# Install dependencies first (if not done)
cd backend
poetry install
cd ..
# Run verification
python scripts/verify_supabase_setup.py
Expected output:
🔍 Supabase Setup Verification
Step 1: Checking environment variables...
✓ All required environment variables are set
Step 2: Creating Supabase client...
✓ Supabase client created successfully
Step 3: Testing database connection...
✓ Connected successfully (judgments count: 0)
Step 4: Checking PostgreSQL extensions...
✓ Extension 'vector': installed
✓ Extension 'pg_trgm': installed
Step 5: Checking required tables...
✓ Table 'judgments': exists
✓ Table 'profiles': exists
Step 6: Checking Row Level Security...
RLS check requires direct SQL access (assumed enabled)
Step 7: Checking database functions...
✓ Function 'search_judgments_by_embedding': exists
✓ Function 'search_judgments_by_text': exists
✓ Function 'search_judgments_hybrid': exists
✓ Function 'get_judgment_facets': exists
Step 8: Checking Supabase Auth...
✓ Auth schema initialized (0 users)
✅ All checks passed! Supabase is properly configured.
Detailed Setup¶
Database Schema Overview¶
The Juddges App uses the following database structure:
Tables¶
public.judgments- Core table for court decisions- Fields:
case_number,jurisdiction,court_name,decision_date,full_text, etc. - Vector column:
embedding(1536-dim for semantic search) -
Supports Polish and UK judgments
-
public.profiles- User profiles linked toauth.users - Auto-created when users sign up
- Stores additional metadata, preferences, and roles
Extensions¶
vector(pgvector) - For semantic similarity searchpg_trgm- For fuzzy text matching
Search Functions¶
search_judgments_by_embedding()- Semantic/vector searchsearch_judgments_by_text()- Full-text searchsearch_judgments_hybrid()- Combined vector + text search with 11+ filtersget_judgment_facets()- Dynamic facet counts for filter UI
Row Level Security (RLS)¶
- Public Read: Anyone can read judgments (no auth required)
- Authenticated Write: Only logged-in users can insert/update
- Service Role: Backend has full access for bulk operations
Authentication Setup¶
Supabase Auth is pre-configured with:
- Email/Password authentication enabled
- User profiles auto-created on signup
- JWT-based sessions with refresh tokens
- SSO support (optional, configure via Dashboard)
Enable Email Confirmations (Optional)¶
By default, email confirmation is disabled for faster development. To enable:
- Go to Authentication → Providers → Email
- Toggle "Confirm email" to ON
- Configure email templates under Authentication → Email Templates
Configure OAuth Providers (Optional)¶
To add Google, GitHub, or other OAuth:
- Go to Authentication → Providers
- Enable desired provider (e.g., Google)
- Add OAuth credentials from provider console
- Update
site_urlandredirect_urlsin Authentication → URL Configuration
Verification¶
Manual Verification Steps¶
1. Check Database Tables¶
You should see:
- judgments table
- profiles table
2. Test Database Connection¶
# Using psql (if you have PostgreSQL client)
npx supabase db remote psql
# Then run:
SELECT table_name FROM information_schema.tables WHERE table_schema = 'public';
3. Verify Extensions¶
Expected:
4. Check RLS Policies¶
Expected policies:
- Public read access for judgments
- Authenticated users can insert judgments
- Authenticated users can update judgments
- Service role has full access
- Users can view own profile
- Users can update own profile
5. Test Auth¶
Create a test user via the dashboard or API:
Then verify in Authentication → Users dashboard.
Automated Verification¶
Run the Python verification script:
This checks: - ✅ Environment variables - ✅ Database connectivity - ✅ Extensions - ✅ Tables existence - ✅ Functions availability - ✅ Auth schema
Troubleshooting¶
Issue: "Failed to link project"¶
Solution: Ensure you're using the correct project-ref. Find it in:
- Supabase Dashboard URL: https://supabase.com/dashboard/project/YOUR-PROJECT-REF
- Settings → General → Project Reference ID
Issue: "Migration failed: relation already exists"¶
Solution: Your database already has some tables. You can:
Option A: Reset local database and re-apply migrations
Option B: Manually drop conflicting tables (⚠️ destructive)
Then re-run:
Issue: "Extension 'vector' does not exist"¶
Solution: Enable pgvector extension via dashboard or SQL:
- Go to Database → Extensions in Supabase Dashboard
- Search for "vector"
- Click "Enable"
Or via SQL:
Issue: "Environment variables not set"¶
Solution:
- Verify
.envfile exists in project root - Check that values don't contain placeholders like
your-*orplaceholder - Restart your development server to pick up new env vars:
Issue: "Auth users table does not exist"¶
Solution: Supabase Auth schema is managed automatically. If it's missing:
- Check that your project is fully initialized (wait 2-3 minutes after creation)
- Verify you're on a paid plan if using advanced auth features
- Contact Supabase support if issue persists
Issue: "Function search_judgments_hybrid does not exist"¶
Solution: Re-apply migrations to create search functions:
Or run the specific migration manually:
Next Steps¶
Once Supabase is set up:
-
Ingest Sample Data: Load court judgments from HuggingFace datasets
-
Start Development Servers:
-
Test Authentication: Visit
http://localhost:3007/auth/loginand create a user -
Test Search: Visit
http://localhost:3007/searchand try semantic search
Additional Resources¶
- Supabase Docs: https://supabase.com/docs
- pgvector Guide: https://github.com/pgvector/pgvector
- Supabase CLI Reference: https://supabase.com/docs/reference/cli
- Project README: See
README.mdfor general setup - Data Ingestion Guide: See
DATA_INGESTION_GUIDE.mdfor loading judgments
Support¶
If you encounter issues not covered here:
- Check Supabase Discord
- Review GitHub Issues
- Open an issue in this project's repository