IntegraChat / SUPABASE_MIGRATION_COMPLETE.md
nothingworry's picture
Migrate admin rules and analytics to Supabase
611e2c1
|
raw
history blame
4.07 kB

Supabase Migration Complete βœ…

After running the migration, your data is now in Supabase. This document explains how to ensure all future data is saved to Supabase instead of SQLite.

βœ… What's Already Configured

Both RulesStore and AnalyticsStore automatically detect and use Supabase when credentials are available. They will:

  1. Check for Supabase credentials in your .env file
  2. Use Supabase if available (preferred)
  3. Fall back to SQLite only if Supabase is not configured

πŸ”§ Required Configuration

To ensure Supabase is used for all future data, make sure your .env file has:

# Required for runtime (REST API)
SUPABASE_URL=https://your-project-id.supabase.co
SUPABASE_SERVICE_KEY=your_service_role_key_here

# Optional: For direct PostgreSQL connection (migration only)
POSTGRESQL_URL=postgresql://postgres:password@db.xxxxx.supabase.co:5432/postgres

Important:

  • SUPABASE_URL and SUPABASE_SERVICE_KEY are required for runtime
  • POSTGRESQL_URL is optional (only needed for migration script)
  • Both stores use the Supabase REST API at runtime, not direct PostgreSQL

βœ… Verify Configuration

Run the verification script to confirm Supabase is configured:

python verify_supabase_setup.py

This will show:

  • βœ… Which backend each store is using
  • ⚠️ Any missing configuration
  • πŸ“‹ Summary of what will be saved where

πŸš€ After Configuration

  1. Restart your services:

    # Stop your FastAPI server
    # Stop your MCP server
    # Then restart them
    
  2. Check startup logs: You should see messages like:

    βœ… RulesStore: Using Supabase backend
    βœ… AnalyticsStore: Using Supabase backend
    βœ… AgentOrchestrator Analytics: Using Supabase backend
    
  3. Test by adding data:

    • Add a rule via the admin panel
    • Make a query to generate analytics
    • Check Supabase Dashboard β†’ Table Editor to verify data appears

πŸ“Š Where Data is Saved

Data Type Storage Location Configuration
Admin Rules Supabase admin_rules table SUPABASE_URL + SUPABASE_SERVICE_KEY
Analytics Events Supabase analytics tables SUPABASE_URL + SUPABASE_SERVICE_KEY
Tool Usage Supabase tool_usage_events SUPABASE_URL + SUPABASE_SERVICE_KEY
Red Flags Supabase redflag_violations SUPABASE_URL + SUPABASE_SERVICE_KEY
RAG Searches Supabase rag_search_events SUPABASE_URL + SUPABASE_SERVICE_KEY
Agent Queries Supabase agent_query_events SUPABASE_URL + SUPABASE_SERVICE_KEY

πŸ” Troubleshooting

Data still going to SQLite?

  1. Check your .env file:

    # Make sure these are set (no quotes, no spaces)
    SUPABASE_URL=https://xxxxx.supabase.co
    SUPABASE_SERVICE_KEY=eyJ... (full key)
    
  2. Verify credentials:

    python verify_supabase_key.py
    
  3. Check startup logs: Look for warnings like:

    ⚠️  RulesStore: Using SQLite backend
    

    This means Supabase credentials are missing or invalid.

  4. Restart services: Environment variables are loaded at startup. After changing .env, restart your services.

Tables don't exist?

If you see errors about missing tables:

  1. Go to Supabase Dashboard β†’ SQL Editor
  2. Run supabase_admin_rules_table.sql (for rules)
  3. Run supabase_analytics_tables.sql (for analytics)

API Key errors?

  • Make sure you're using the service_role key (not anon key)
  • Key should be ~200+ characters long
  • No quotes or spaces around the value in .env

πŸ“ Summary

βœ… Migration complete - Your existing data is in Supabase
βœ… Auto-detection enabled - Stores automatically use Supabase when configured
βœ… Startup logging - You'll see which backend is being used
βœ… Verification script - Run verify_supabase_setup.py to check configuration

Next time you add rules or generate analytics, they will automatically be saved to Supabase! πŸŽ‰