| |
| """ |
| 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(password) |
| |
| |
| 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') |
| ) |
| |
| |
| 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) |
| |
| |
| password = input("Enter your Supabase database password: ") |
| |
| if not password: |
| print("β Password is required!") |
| sys.exit(1) |
| |
| |
| 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() |
|
|