| |
| """ |
| Discover existing tables in your Supabase database |
| """ |
|
|
| from supabase import create_client, Client |
| import pandas as pd |
|
|
| def discover_database_structure(): |
| """Discover what tables and data exist in the Supabase database""" |
| |
| url = "https://bnjblzcqaumctpehgoid.supabase.co" |
| key = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImJuamJsemNxYXVtY3RwZWhnb2lkIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NTgyOTA0OTQsImV4cCI6MjA3Mzg2NjQ5NH0.L4wPzuBj9dlSKpYxO1eDX-57KcP0mbNfN8stmTB-STM" |
| |
| print("π Discovering your Supabase Database Structure") |
| print("=" * 60) |
| |
| try: |
| |
| supabase: Client = create_client(url, key) |
| print("β
Connected to Supabase!") |
| |
| |
| common_tables = [ |
| 'users', 'profiles', 'posts', 'products', 'orders', 'customers', |
| 'employees', 'tasks', 'projects', 'categories', 'items', 'data', |
| 'records', 'entries', 'logs', 'events', 'notifications', 'settings', |
| 'comments', 'reviews', 'messages', 'files', 'uploads', 'content', |
| 'articles', 'pages', 'menu', 'navigation', 'contacts', 'addresses' |
| ] |
| |
| existing_tables = [] |
| |
| print("\nπ Checking for existing tables...") |
| |
| for table_name in common_tables: |
| try: |
| |
| result = supabase.table(table_name).select("*").limit(1).execute() |
| |
| |
| existing_tables.append(table_name) |
| |
| |
| data_count = len(result.data) if result.data else 0 |
| print(f" β
Found table: '{table_name}' (sample data: {data_count} rows)") |
| |
| |
| if result.data and len(result.data) > 0: |
| columns = list(result.data[0].keys()) |
| print(f" Columns: {', '.join(columns[:10])}{'...' if len(columns) > 10 else ''}") |
| |
| except Exception as e: |
| |
| if "PGRST205" in str(e): |
| continue |
| else: |
| print(f" β οΈ Error accessing '{table_name}': {str(e)}") |
| |
| if existing_tables: |
| print(f"\nπ Found {len(existing_tables)} accessible tables:") |
| for table in existing_tables: |
| print(f" - {table}") |
| |
| print("\nπ Getting sample data from first table...") |
| first_table = existing_tables[0] |
| try: |
| sample_result = supabase.table(first_table).select("*").limit(5).execute() |
| if sample_result.data: |
| df = pd.DataFrame(sample_result.data) |
| print(f"\nSample data from '{first_table}':") |
| print(df.to_string(index=False)) |
| else: |
| print(f"Table '{first_table}' exists but has no data") |
| |
| except Exception as e: |
| print(f"Error getting sample data: {str(e)}") |
| else: |
| print("\nβ οΈ No common tables found or accessible with current permissions.") |
| print("Your database might have custom table names or require different permissions.") |
| |
| |
| print("\nπ Attempting alternative discovery methods...") |
| try: |
| |
| for rpc_name in ['get_tables', 'list_tables', 'show_tables']: |
| try: |
| rpc_result = supabase.rpc(rpc_name).execute() |
| print(f"β
RPC function '{rpc_name}' available: {rpc_result.data}") |
| break |
| except: |
| continue |
| except Exception as e: |
| print("No table discovery RPC functions found.") |
| |
| return existing_tables |
| |
| except Exception as e: |
| print(f"β Error discovering database: {str(e)}") |
| return [] |
|
|
| if __name__ == "__main__": |
| tables = discover_database_structure() |
| |
| if tables: |
| print(f"\nπ Ready to use Gradio interface with your {len(tables)} tables!") |
| print("Run: python app_supabase.py") |
| else: |
| print("\nπ‘ Tips:") |
| print("1. Check your Supabase dashboard to see table names") |
| print("2. Ensure Row Level Security (RLS) policies allow read access") |
| print("3. Use the Gradio interface to try custom table names") |
|
|