Spaces:
Running

microfunnel-api / backend /scripts /check_supabase_bucket.py
axeronis
Fix: Telegram notification bugs - add missing token parameter
01bc36c
Raw History Blame Contribute Delete
2.56 kB
"""
Quick script to check if Supabase bucket is configured correctly.
Run: python -m scripts.check_supabase_bucket
"""
import sys
from app.core.supabase import supabase_client
def main():
print("=" * 60)
print("Supabase Bucket Configuration Check")
print("=" * 60)
if not supabase_client:
print("❌ Supabase client not initialized!")
print(" Check SUPABASE_URL and SUPABASE_KEY in .env")
return False
print("βœ… Supabase client initialized")
# List buckets
try:
buckets = supabase_client.storage.list_buckets()
bucket_names = [b.name for b in buckets]
print(f"\nπŸ“¦ Available buckets: {bucket_names}")
if "chat-attachments" not in bucket_names:
print("\n❌ 'chat-attachments' bucket NOT found!")
print(" Create it in Supabase Dashboard:")
print(" 1. Storage β†’ New bucket")
print(" 2. Name: chat-attachments")
print(" 3. Public: ON")
return False
print("βœ… 'chat-attachments' bucket exists")
except Exception as e:
print(f"❌ Error listing buckets: {e}")
return False
# Test upload
try:
test_path = "test/check.txt"
test_content = b"Test upload from check script"
print(f"\n⬆️ Testing upload to {test_path}...")
result = supabase_client.storage.from_("chat-attachments").upload(
path=test_path,
file=test_content,
file_options={"content-type": "text/plain", "upsert": "true"}
)
print(f"βœ… Upload successful!")
# Get public URL
public_url = supabase_client.storage.from_("chat-attachments").get_public_url(test_path)
print(f"βœ… Public URL: {public_url}")
# Cleanup
print(f"\n🧹 Cleaning up test file...")
supabase_client.storage.from_("chat-attachments").remove([test_path])
print("βœ… Cleanup complete")
except Exception as e:
print(f"❌ Upload failed: {e}")
print("\n Possible issues:")
print(" 1. Bucket is not public")
print(" 2. Missing RLS policy for INSERT")
print(" 3. SUPABASE_KEY doesn't have sufficient permissions")
return False
print("\n" + "=" * 60)
print("βœ… All checks passed! Bucket is configured correctly.")
print("=" * 60)
return True
if __name__ == "__main__":
success = main()
sys.exit(0 if success else 1)