File size: 1,898 Bytes
1623af6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
58
59
60
61
62
63
64
65
66
#!/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()