Spaces:
Sleeping
Sleeping
| #!/usr/bin/env python3 | |
| """ | |
| Helper script to create or update .env file with Supabase credentials. | |
| """ | |
| import os | |
| from pathlib import Path | |
| def main(): | |
| print("=" * 70) | |
| print("Supabase .env Setup Helper") | |
| print("=" * 70) | |
| print() | |
| env_file = Path(".env") | |
| env_example = Path("env.example") | |
| # Check if .env already exists | |
| if env_file.exists(): | |
| print("β οΈ .env file already exists!") | |
| response = input(" Do you want to update it? (y/n): ").strip().lower() | |
| if response != 'y': | |
| print(" Skipping. Edit .env manually if needed.") | |
| return | |
| print() | |
| # Read existing .env if it exists | |
| existing_vars = {} | |
| if env_file.exists(): | |
| with open(env_file, 'r') as f: | |
| for line in f: | |
| line = line.strip() | |
| if line and not line.startswith('#') and '=' in line: | |
| key, value = line.split('=', 1) | |
| existing_vars[key.strip()] = value.strip() | |
| print("Enter your Supabase credentials:") | |
| print("(You can find these at: https://app.supabase.com β Your Project β Settings β API)") | |
| print() | |
| # Get Supabase URL | |
| current_url = existing_vars.get('SUPABASE_URL', '') | |
| if current_url: | |
| print(f"Current SUPABASE_URL: {current_url[:50]}...") | |
| response = input("Keep current? (y/n): ").strip().lower() | |
| if response == 'y': | |
| supabase_url = current_url | |
| else: | |
| supabase_url = input("Enter SUPABASE_URL (https://xxxxx.supabase.co): ").strip() | |
| else: | |
| supabase_url = input("Enter SUPABASE_URL (https://xxxxx.supabase.co): ").strip() | |
| # Get Supabase Service Key | |
| current_key = existing_vars.get('SUPABASE_SERVICE_KEY', '') | |
| if current_key: | |
| print(f"Current SUPABASE_SERVICE_KEY: {current_key[:20]}...") | |
| response = input("Keep current? (y/n): ").strip().lower() | |
| if response == 'y': | |
| supabase_key = current_key | |
| else: | |
| supabase_key = input("Enter SUPABASE_SERVICE_KEY (service_role key): ").strip() | |
| else: | |
| supabase_key = input("Enter SUPABASE_SERVICE_KEY (service_role key): ").strip() | |
| # Validate | |
| if not supabase_url.startswith('https://'): | |
| print("β οΈ Warning: SUPABASE_URL should start with https://") | |
| if not supabase_key.startswith('eyJ'): | |
| print("β οΈ Warning: SUPABASE_SERVICE_KEY should start with 'eyJ' (JWT token)") | |
| print() | |
| print("π Creating/updating .env file...") | |
| # Read env.example as template | |
| lines = [] | |
| if env_example.exists(): | |
| with open(env_example, 'r') as f: | |
| lines = f.readlines() | |
| else: | |
| # Create basic template | |
| lines = [ | |
| "# IntegraChat Environment Variables\n", | |
| "# Supabase Configuration\n", | |
| "SUPABASE_URL=\n", | |
| "SUPABASE_SERVICE_KEY=\n", | |
| ] | |
| # Update or add Supabase variables | |
| updated_lines = [] | |
| url_found = False | |
| key_found = False | |
| for line in lines: | |
| if line.startswith('SUPABASE_URL='): | |
| updated_lines.append(f'SUPABASE_URL={supabase_url}\n') | |
| url_found = True | |
| elif line.startswith('SUPABASE_SERVICE_KEY='): | |
| updated_lines.append(f'SUPABASE_SERVICE_KEY={supabase_key}\n') | |
| key_found = True | |
| else: | |
| updated_lines.append(line) | |
| # Add if not found | |
| if not url_found: | |
| updated_lines.append(f'SUPABASE_URL={supabase_url}\n') | |
| if not key_found: | |
| updated_lines.append(f'SUPABASE_SERVICE_KEY={supabase_key}\n') | |
| # Write .env file | |
| with open(env_file, 'w') as f: | |
| f.writelines(updated_lines) | |
| print(f"β .env file created/updated at: {env_file.absolute()}") | |
| print() | |
| print("Next steps:") | |
| print("1. Make sure your Supabase project is active (not paused)") | |
| print("2. Create the tables in Supabase:") | |
| print(" - Run supabase_admin_rules_table.sql in SQL Editor") | |
| print(" - Run supabase_analytics_tables.sql in SQL Editor") | |
| print("3. Test the connection:") | |
| print(" python check_supabase_rules.py") | |
| print("4. Run the migration:") | |
| print(" python migrate_sqlite_to_supabase.py") | |
| if __name__ == "__main__": | |
| main() | |