Skip to main content

CLI Database Access

Guide for inserting/querying test data directly via CLI.

Prerequisites

  1. Install PostgreSQL (for psql access):
    brew install postgresql
    
  2. Verify .env file has these keys:
    • EXPO_PUBLIC_SUPABASE_URL
    • EXPO_PUBLIC_SUPABASE_KEY (NOT ANON_KEY)

Insert Test Data

Use the pre-built script:
bun run scripts/insert-test-data.ts
This will:
  • Load environment variables from .env
  • Insert a complete test journal entry
  • Display the created entry ID and details

Script Location

scripts/insert-test-data.ts - Inserts a realistic test entry with:
  • 8 responses (emotions, circumstance, thoughts, beliefs, truth, prayer, etc.)
  • Proper title generation
  • Completed status

Modify Test Data

Edit scripts/insert-test-data.ts to customize:
  • User/org IDs (lines 41-42)
  • Response content (lines 46-78)
  • Mood selections (lines 48-52)

Troubleshooting

”supabaseKey is required”

  • Cause: Env variable not loading correctly
  • Fix: Ensure .env has EXPO_PUBLIC_SUPABASE_KEY (not ANON_KEY)

“Permission denied”

  • Cause: RLS policies blocking insert
  • Fix: Temporarily disable RLS (already done for debugging)

Direct SQL Access (Advanced)

If you need raw SQL access, use psql with connection string:
# Get connection info from Supabase dashboard
psql "postgresql://[user]:[password]@[host]:[port]/[database]"
⚠️ Not recommended - use the script instead for safety.

Cleanup

To delete test entries:
DELETE FROM flow_sessions WHERE ai_title LIKE 'TEST CLI:%';
Or run via script:
bun run scripts/cleanup-test-data.ts
(Create this script if needed)