testDB / test_connection.py
jaannawaz
Initial Supabase Gradio interface with secure configuration
1623af6
#!/usr/bin/env python3
"""
Test script for Supabase connection
Run this script to test your database connection before deploying
"""
import os
import sys
from config import setup_environment_variables
import psycopg2
def test_connection_with_password(password: str):
"""Test database connection with provided password"""
try:
# Setup environment variables
setup_environment_variables(password)
# Test connection
conn = psycopg2.connect(
host=os.getenv('DB_HOST'),
port=os.getenv('DB_PORT'),
database=os.getenv('DB_NAME'),
user=os.getenv('DB_USER'),
password=os.getenv('DB_PASSWORD')
)
# Test query
cursor = conn.cursor()
cursor.execute("SELECT version();")
version = cursor.fetchone()
cursor.close()
conn.close()
print("βœ… Database connection successful!")
print(f"PostgreSQL version: {version[0]}")
return True
except Exception as e:
print(f"❌ Database connection failed: {str(e)}")
return False
def main():
print("πŸ” Testing Supabase Database Connection")
print("=" * 50)
# Get password from user
password = input("Enter your Supabase database password: ")
if not password:
print("❌ Password is required!")
sys.exit(1)
# Test connection
if test_connection_with_password(password):
print("\nπŸš€ Ready to deploy!")
print("\nNext steps:")
print("1. Set DB_PASSWORD as a secret in your Hugging Face Space")
print("2. Push your code to the repository")
print("3. Your Gradio app will be available at your Space URL")
else:
print("\n⚠️ Please check your database credentials and try again")
if __name__ == "__main__":
main()