Spaces:
Paused
Paused
Download scripts/setup_supabase_simple.py from VAH6002/ai_data_scientist: direct link, hf CLI and curl.
- Browser
- Download file 6.65 kB
-
https://huggingface.co/spaces/VAH6002/ai_data_scientist/resolve/main/scripts/setup_supabase_simple.py
- Command line
-
hf download hf://spaces/VAH6002/ai_data_scientist/scripts/setup_supabase_simple.py
-
curl -L -o setup_supabase_simple.py https://huggingface.co/spaces/VAH6002/ai_data_scientist/resolve/main/scripts/setup_supabase_simple.py
6.65 kB
| #!/usr/bin/env python3 | |
| """ | |
| Simple Supabase setup validation script. | |
| Checks configuration without requiring actual database connection. | |
| """ | |
| import os | |
| import sys | |
| from pathlib import Path | |
| # Add project root to path | |
| project_root = Path(__file__).parent.parent | |
| sys.path.insert(0, str(project_root)) | |
| from shared.config import settings | |
| def check_environment_variables(): | |
| """Check that all required environment variables are set.""" | |
| print("π Checking environment variables...") | |
| required_vars = [ | |
| ('SUPABASE_URL', settings.supabase_url), | |
| ('SUPABASE_ANON_KEY', settings.supabase_anon_key), | |
| ('SUPABASE_SERVICE_ROLE_KEY', settings.supabase_service_role_key) | |
| ] | |
| all_set = True | |
| for var_name, var_value in required_vars: | |
| if not var_value or var_value in ['your-project-id', 'your-anon-key-here', 'your-service-role-key-here', '**** **** **** ****']: | |
| print(f"β {var_name} is not set or contains placeholder value") | |
| all_set = False | |
| else: | |
| print(f"β {var_name} is configured") | |
| return all_set | |
| def validate_supabase_url(): | |
| """Validate Supabase URL format.""" | |
| print("\nπ Validating Supabase URL format...") | |
| url = settings.supabase_url | |
| if not url: | |
| print("β SUPABASE_URL is not set") | |
| return False | |
| if not url.startswith('https://') or not url.endswith('.supabase.co'): | |
| print(f"β Invalid Supabase URL format: {url}") | |
| print(" Expected format: https://your-project-id.supabase.co") | |
| return False | |
| print(f"β Supabase URL format is valid: {url}") | |
| return True | |
| def validate_api_keys(): | |
| """Validate API key formats.""" | |
| print("\nπ Validating API key formats...") | |
| anon_key = settings.supabase_anon_key | |
| service_key = settings.supabase_service_role_key | |
| valid = True | |
| # Check anon key | |
| if not anon_key or len(anon_key) < 100: | |
| print("β SUPABASE_ANON_KEY appears to be invalid (too short)") | |
| valid = False | |
| elif not anon_key.startswith('eyJ'): | |
| print("β SUPABASE_ANON_KEY doesn't appear to be a JWT token") | |
| valid = False | |
| else: | |
| print("β SUPABASE_ANON_KEY format looks valid") | |
| # Check service role key | |
| if not service_key or len(service_key) < 100: | |
| print("β SUPABASE_SERVICE_ROLE_KEY appears to be invalid (too short)") | |
| valid = False | |
| elif not service_key.startswith('eyJ'): | |
| print("β SUPABASE_SERVICE_ROLE_KEY doesn't appear to be a JWT token") | |
| valid = False | |
| else: | |
| print("β SUPABASE_SERVICE_ROLE_KEY format looks valid") | |
| return valid | |
| def check_schema_file(): | |
| """Check that the schema file exists.""" | |
| print("\nπ Checking database schema file...") | |
| schema_file = project_root / "shared" / "sql" / "supabase_complete_schema.sql" | |
| if not schema_file.exists(): | |
| print(f"β Schema file not found: {schema_file}") | |
| return False | |
| # Check file size | |
| file_size = schema_file.stat().st_size | |
| if file_size < 1000: # Should be much larger | |
| print(f"β Schema file seems too small: {file_size} bytes") | |
| return False | |
| print(f"β Schema file found: {schema_file} ({file_size} bytes)") | |
| return True | |
| def print_setup_instructions(): | |
| """Print setup instructions.""" | |
| print("\nπ Supabase Setup Instructions:") | |
| print("=" * 50) | |
| print("\n1. Create Supabase Project:") | |
| print(" - Go to https://supabase.com") | |
| print(" - Click 'New Project'") | |
| print(" - Choose organization and project name") | |
| print(" - Set database password") | |
| print(" - Wait for project creation (2-3 minutes)") | |
| print("\n2. Get API Credentials:") | |
| print(" - Go to Project Settings > API") | |
| print(" - Copy Project URL") | |
| print(" - Copy 'anon public' key") | |
| print(" - Copy 'service_role secret' key") | |
| print("\n3. Update Environment Variables:") | |
| print(" - Edit your .env file") | |
| print(" - Replace placeholder values with actual credentials") | |
| print(" - Save the file") | |
| print("\n4. Apply Database Schema:") | |
| print(" - Go to your Supabase project dashboard") | |
| print(" - Navigate to SQL Editor") | |
| print(" - Copy contents of shared/sql/supabase_complete_schema.sql") | |
| print(" - Paste and execute in SQL Editor") | |
| print("\n5. Configure Authentication (Optional):") | |
| print(" - Go to Authentication > Providers") | |
| print(" - Configure Clerk integration if needed") | |
| print("\n6. Enable Real-time (Optional):") | |
| print(" - Go to Database > Replication") | |
| print(" - Enable real-time for progress_events table") | |
| print(" - Enable real-time for analysis_sessions table") | |
| print("\n7. Test Setup:") | |
| print(" - Run: python scripts/validate_supabase_setup.py") | |
| print(" - Run: python -m pytest tests/test_supabase_integration.py") | |
| def main(): | |
| """Main validation function.""" | |
| print("π Supabase Setup Validation") | |
| print("=" * 40) | |
| # Check environment variables | |
| env_ok = check_environment_variables() | |
| # Validate URL format | |
| url_ok = validate_supabase_url() | |
| # Validate API keys | |
| keys_ok = validate_api_keys() | |
| # Check schema file | |
| schema_ok = check_schema_file() | |
| # Summary | |
| print("\nπ Validation Summary:") | |
| print("=" * 30) | |
| checks = [ | |
| ("Environment Variables", env_ok), | |
| ("Supabase URL Format", url_ok), | |
| ("API Key Formats", keys_ok), | |
| ("Schema File", schema_ok) | |
| ] | |
| passed = sum(1 for _, ok in checks if ok) | |
| total = len(checks) | |
| for check_name, ok in checks: | |
| status = "β PASS" if ok else "β FAIL" | |
| print(f"{check_name}: {status}") | |
| print(f"\nOverall: {passed}/{total} checks passed") | |
| if passed == total: | |
| print("\nπ Configuration looks good!") | |
| print("Next steps:") | |
| print("1. Apply the database schema in Supabase dashboard") | |
| print("2. Test connection with: python scripts/validate_supabase_setup.py") | |
| else: | |
| print(f"\nβ οΈ {total - passed} issues found.") | |
| print("Please fix the issues above before proceeding.") | |
| print_setup_instructions() | |
| return passed == total | |
| if __name__ == "__main__": | |
| success = main() | |
| sys.exit(0 if success else 1) |