Skip to content

Commit 8427f7a

Browse files
Update to use Supabase connection pooler with SSL mode
1 parent 440604b commit 8427f7a

File tree

3 files changed

+98
-7
lines changed

3 files changed

+98
-7
lines changed

docs/GITHUB_SECRETS.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,17 @@ You need to add the following secrets to your GitHub repository for the workflow
88

99
### Database Connection Secrets (for Data Ingestion)
1010

11-
1. **DB_HOST**: `db.brettblayvzvgswearre.supabase.co`
12-
- Your Supabase PostgreSQL database host
13-
- Note: Use the `db.` prefix, not the API URL
11+
1. **DB_HOST**: `aws-1-us-east-1.pooler.supabase.com`
12+
- Your Supabase connection pooler hostname
13+
- Get this from: Supabase Dashboard → Settings → Database → Connection String → Session pooler
14+
- Format: `aws-[number]-[region].pooler.supabase.com`
1415

1516
2. **DB_PORT**: `5432`
16-
- PostgreSQL default port
17+
- Connection pooler port (5432 for transaction mode, 6543 for session mode)
1718

18-
3. **DB_USER**: `postgres`
19-
- Default PostgreSQL username
19+
3. **DB_USER**: `postgres.brettblayvzvgswearre`
20+
- Username format: `postgres.[project-ref]`
21+
- Get your project ref from Supabase Dashboard URL or connection string
2022

2123
4. **DB_PASSWORD**: `YOUR_DATABASE_PASSWORD`
2224
- Your Supabase database password (the one you set when creating the project)

flask-api/scripts/ingest_elo_and_fpl.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ def get_db_connection():
5757
logger.error("DB_PASSWORD environment variable is not set!")
5858
raise ValueError("DB_PASSWORD is required but not set")
5959

60-
connection = psycopg2.connect(**DB_CONFIG)
60+
# Add SSL mode for Supabase connections
61+
connection = psycopg2.connect(**DB_CONFIG, sslmode='require')
6162
logger.info("Successfully connected to PostgreSQL database")
6263
return connection
6364
except Error as e:
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#!/usr/bin/env python3
2+
"""
3+
Test database connection script
4+
Tests if we can connect to Supabase PostgreSQL database
5+
"""
6+
import os
7+
import sys
8+
import psycopg2
9+
from psycopg2 import Error
10+
11+
# Database configuration
12+
DB_CONFIG = {
13+
'host': os.getenv('DB_HOST', 'localhost'),
14+
'user': os.getenv('DB_USER', 'postgres'),
15+
'password': os.getenv('DB_PASSWORD'),
16+
'database': os.getenv('DB_NAME', 'postgres'),
17+
'port': int(os.getenv('DB_PORT', '5432'))
18+
}
19+
20+
def test_connection():
21+
"""Test database connection"""
22+
print("=" * 60)
23+
print("Testing Supabase PostgreSQL Connection")
24+
print("=" * 60)
25+
26+
# Check environment variables
27+
print("\n📋 Environment Variables:")
28+
print(f" DB_HOST: {DB_CONFIG['host']}")
29+
print(f" DB_PORT: {DB_CONFIG['port']}")
30+
print(f" DB_USER: {DB_CONFIG['user']}")
31+
print(f" DB_NAME: {DB_CONFIG['database']}")
32+
print(f" DB_PASSWORD: {'*' * len(DB_CONFIG['password']) if DB_CONFIG['password'] else 'NOT SET'}")
33+
34+
if not DB_CONFIG['password']:
35+
print("\n❌ ERROR: DB_PASSWORD environment variable is not set!")
36+
print(" Set it with: export DB_PASSWORD='your-password'")
37+
return False
38+
39+
# Test connection
40+
print("\n🔌 Attempting to connect...")
41+
try:
42+
# Add SSL mode for Supabase connections
43+
connection = psycopg2.connect(**DB_CONFIG, sslmode='require')
44+
print("✅ Connection successful!")
45+
46+
# Test a simple query
47+
cursor = connection.cursor()
48+
cursor.execute("SELECT version();")
49+
version = cursor.fetchone()
50+
print(f"✅ PostgreSQL version: {version[0][:50]}...")
51+
52+
# Check if player table exists
53+
cursor.execute("""
54+
SELECT EXISTS (
55+
SELECT FROM information_schema.tables
56+
WHERE table_name = 'player'
57+
);
58+
""")
59+
table_exists = cursor.fetchone()[0]
60+
61+
if table_exists:
62+
cursor.execute("SELECT COUNT(*) FROM player;")
63+
player_count = cursor.fetchone()[0]
64+
print(f"✅ Player table exists with {player_count} players")
65+
else:
66+
print("⚠️ Player table does not exist yet (this is OK if database is new)")
67+
68+
cursor.close()
69+
connection.close()
70+
print("\n✅ All tests passed!")
71+
return True
72+
73+
except Error as e:
74+
print(f"\n❌ Connection failed: {e}")
75+
print("\n💡 Troubleshooting:")
76+
print(" 1. Check that DB_HOST is correct (should start with 'db.')")
77+
print(" 2. Verify DB_PASSWORD is correct")
78+
print(" 3. Ensure your IP is allowed in Supabase (Settings → Database → Connection Pooling)")
79+
print(" 4. Check that the database is running in Supabase dashboard")
80+
return False
81+
except Exception as e:
82+
print(f"\n❌ Unexpected error: {e}")
83+
return False
84+
85+
if __name__ == "__main__":
86+
success = test_connection()
87+
sys.exit(0 if success else 1)
88+

0 commit comments

Comments
 (0)