""" 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)