import os from dotenv import load_dotenv import requests import sys # Load .env load_dotenv() SUPABASE_URL = os.getenv("VITE_SUPABASE_URL") SUPABASE_KEY = os.getenv("VITE_SUPABASE_ANON_KEY") if not SUPABASE_URL or not SUPABASE_KEY: print("❌ Error: Credentials not found in .env") sys.exit(1) print(f"🔄 Testing connection to: {SUPABASE_URL}") headers = { "apikey": SUPABASE_KEY, "Authorization": f"Bearer {SUPABASE_KEY}" } # Try to list tables (or just a basic query to health check) # Since we might not have tables yet, querying '/' usually returns a 404 or doc, # but querying '/rest/v1/' should give us info or at least connect. # A better check is to query a table that doesn't exist and expect a specific error, OR # if we created the table via dashboard, query it. # As a handshake, we will try to query the REST endpoint top level. try: response = requests.get(f"{SUPABASE_URL}/rest/v1/", headers=headers) # 200 or 404 is fine as long as it's not 401 Unauthorized or Connection Error if response.status_code in [200, 404]: print(f"✅ Connection Successful! (Status: {response.status_code})") # Try to query 'reservations' table to see if it exists resp_table = requests.get(f"{SUPABASE_URL}/rest/v1/reservations?select=count", headers=headers) if resp_table.status_code == 200: print("✅ Table 'reservations' found.") elif resp_table.status_code == 404: print("âš ī¸ Table 'reservations' NOT found. (You need to run db_schema.sql)") else: print(f"â„šī¸ Table check status: {resp_table.status_code}") elif response.status_code == 401: print("❌ Authorization Failed (401). Check your Anon Key.") sys.exit(1) else: print(f"âš ī¸ Unexpected Status: {response.status_code}") except Exception as e: print(f"❌ Connection Error: {e}") sys.exit(1)