Spaces:
Sleeping
Sleeping
File size: 1,940 Bytes
49462f7 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
import os
import sys
from datetime import datetime, timezone
from supabase import create_client, Client
def main():
print("--- Supabase Connection Test ---")
# 1. Check Env Vars
url = os.getenv("SUPABASE_URL")
key = os.getenv("SUPABASE_ANON_KEY") or os.getenv("SUPABASE_SERVICE_ROLE_KEY")
enable_metrics = os.getenv("ENABLE_METRICS_LOGGING", "false").lower() == "true"
print(f"ENABLE_METRICS_LOGGING: {enable_metrics}")
print(f"SUPABASE_URL: {'Set' if url else 'Missing'}")
print(f"SUPABASE_KEY: {'Set' if key else 'Missing'}")
if not url or not key:
print("β Missing Supabase credentials.")
sys.exit(1)
if not enable_metrics:
print("β οΈ ENABLE_METRICS_LOGGING is not true. The backend would skip logging.")
print(" Proceeding with test anyway to verify connection...")
# 2. Connect
try:
supabase: Client = create_client(url, key)
print("β
Supabase client initialized.")
except Exception as e:
print(f"β Failed to initialize client: {e}")
sys.exit(1)
# 3. Test Insert
payload = {
"question": "TEST_CONNECTION_PROBE",
"answer": "This is a test row from scripts/test_supabase_connection.py",
"provenance": "test_script",
"user_id": "test_user"
}
print(f"Attempting to insert into 'metrics_chat_answers': {payload}")
try:
response = supabase.table("metrics_chat_answers").insert(payload).execute()
print("β
Insert successful!")
print("Response data:", response.data)
except Exception as e:
print(f"β Insert failed: {e}")
print("Possible causes:")
print(" - Table 'metrics_chat_answers' does not exist.")
print(" - RLS (Row Level Security) blocks insertion for anon key.")
print(" - Triggers or constraints failed.")
if __name__ == "__main__":
main()
|