Files
usda-vision/supabase
salirezav 8f4225a62e feat: Add dynamic host IP detection for Docker Compose and Supabase config
- Add docker-compose.sh wrapper script that auto-detects host IP
- Update docker-compose.yml to use environment variable substitution
- Update Supabase config.toml files to use HOST_SITE_URL and SUPABASE_API_URL env vars
- Add scripts/get-host-ip.sh for IP detection
- Add scripts/set-host-env.sh for environment setup
- Add scripts/supabase-with-env.sh wrapper for Supabase CLI
- Add documentation for Docker Compose environment setup
- Update README.md with new usage instructions
- Replace hardcoded URLs with dynamic environment variables
2025-12-18 19:57:27 -05:00
..

Supabase Database Module

This directory contains all Supabase configuration, migrations, and seed data for the USDA Vision project.

Structure

supabase/
├── config.toml              # Supabase CLI configuration
├── migrations/              # Database migration files (run in order)
│   ├── 00001_extensions_and_utilities.sql
│   ├── 00002_users_and_roles.sql
│   └── ...
├── seed_01_users.sql        # Initial user data
└── seed_02_phase2_experiments.sql  # Initial experiment data

Usage

The Supabase containers are managed by the main docker-compose.yml at the project root. Migrations and seeds are automatically run on startup.

# From project root
docker compose up -d

With Supabase CLI

If you need to use Supabase CLI commands, run them from the project root (this directory's parent):

# From project root
cd /path/to/USDA-VISION

# Start Supabase (if not using docker-compose)
supabase start

# Run migrations manually
supabase db reset

# Generate types
supabase gen types typescript --local > management-dashboard-web-app/src/types/supabase.ts

Note: The Supabase CLI looks for the supabase/ directory in the current working directory. Since we've moved it to the root, you can now run Supabase commands from the project root instead of needing to cd into management-dashboard-web-app.

Migration Workflow

  1. Create a new migration:

    supabase migration new migration_name
    
  2. Apply migrations:

    • Automatically via docker-compose on startup
    • Manually: supabase db reset (from project root)
  3. Check migration status:

    supabase migration list
    

Seed Data

Seed files are run automatically after migrations when using docker-compose. They populate the database with initial data:

  • seed_01_users.sql: Creates admin user and initial user profiles
  • seed_02_phase2_experiments.sql: Creates initial experiment data

Configuration

The config.toml file contains all Supabase service configurations:

  • Database port: 54322
  • API port: 54321
  • Studio port: 54323
  • Inbucket (email testing): 54324

See config.toml for detailed configuration options.

Accessing Services

Best Practices

  1. Migrations are versioned: Always use numbered prefixes (e.g., 00001_, 00002_)
  2. Migrations should be idempotent: Use IF NOT EXISTS and CREATE OR REPLACE where possible
  3. Test migrations locally: Always test migrations before committing
  4. Document breaking changes: Add notes in migration files for schema changes