Spaces:
Sleeping
Sleeping
feat: Enhance admin rules with file upload, drag-and-drop, chunk processing, and improved UI
a477044
| """ | |
| Simple script to create admin_rules table in Supabase. | |
| This uses the Supabase Management API or direct SQL execution. | |
| """ | |
| import os | |
| from dotenv import load_dotenv | |
| import httpx | |
| import json | |
| load_dotenv() | |
| SUPABASE_URL = os.getenv("SUPABASE_URL") | |
| SUPABASE_SERVICE_KEY = os.getenv("SUPABASE_SERVICE_KEY") | |
| if not SUPABASE_URL or not SUPABASE_SERVICE_KEY: | |
| print("β Missing Supabase credentials!") | |
| print(" Set SUPABASE_URL and SUPABASE_SERVICE_KEY in .env file") | |
| exit(1) | |
| # Read the SQL file | |
| sql_file = Path("supabase_admin_rules_table.sql") | |
| if not sql_file.exists(): | |
| print(f"β SQL file not found: {sql_file}") | |
| exit(1) | |
| with open(sql_file, "r") as f: | |
| sql_content = f.read() | |
| print("π Connecting to Supabase...") | |
| print(f" URL: {SUPABASE_URL[:50]}...") | |
| # Method 1: Try using Supabase REST API with SQL execution | |
| # Note: This requires the pg_net extension or a custom function | |
| # Most Supabase projects don't allow direct SQL execution via REST API | |
| # Method 2: Use Supabase Python client to execute via RPC | |
| try: | |
| from supabase import create_client | |
| client = create_client(SUPABASE_URL, SUPABASE_SERVICE_KEY) | |
| # Split SQL into individual statements | |
| statements = [s.strip() for s in sql_content.split(";") if s.strip() and not s.strip().startswith("--")] | |
| print(f"\nπ Executing {len(statements)} SQL statements...") | |
| # Execute each statement | |
| # Note: Supabase Python client doesn't support direct SQL execution | |
| # We'll need to use a workaround or manual execution | |
| print("\nβ οΈ Direct SQL execution via Python client is not supported.") | |
| print(" Supabase requires SQL to be executed via the SQL Editor.") | |
| print("\nπ Please follow these steps:") | |
| print(" 1. Go to: https://app.supabase.com") | |
| print(" 2. Select your project") | |
| print(" 3. Click 'SQL Editor' in the left sidebar") | |
| print(" 4. Click 'New query'") | |
| print(" 5. Copy the contents of: supabase_admin_rules_table.sql") | |
| print(" 6. Paste into the SQL Editor") | |
| print(" 7. Click 'Run' (or press Ctrl+Enter)") | |
| print("\nβ After running the SQL, the table will be created!") | |
| except ImportError: | |
| print("β Supabase client not installed") | |
| print(" Run: pip install supabase") | |
| except Exception as e: | |
| print(f"β Error: {e}") | |
| print("\nπ‘ Manual setup required - see instructions above") | |