Skip to content

Commit 17d7269

Browse files
Add database secret validation and better error logging
1 parent a1fbf68 commit 17d7269

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

.github/workflows/data-ingestion.yml

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,29 @@ jobs:
3434
run: |
3535
pip install -r requirements.txt
3636
37+
- name: Verify database secrets
38+
run: |
39+
if [ -z "${{ secrets.DB_HOST }}" ]; then
40+
echo "❌ Error: DB_HOST secret is not set"
41+
exit 1
42+
fi
43+
if [ -z "${{ secrets.DB_PASSWORD }}" ]; then
44+
echo "❌ Error: DB_PASSWORD secret is not set"
45+
exit 1
46+
fi
47+
echo "✅ Database secrets are configured"
48+
echo "DB_HOST: ${{ secrets.DB_HOST }}"
49+
echo "DB_USER: ${{ secrets.DB_USER || 'postgres' }}"
50+
echo "DB_NAME: ${{ secrets.DB_NAME || 'postgres' }}"
51+
echo "DB_PORT: ${{ secrets.DB_PORT || '5432' }}"
52+
3753
- name: Run data ingestion
3854
working-directory: flask-api
3955
env:
4056
DB_HOST: ${{ secrets.DB_HOST }}
41-
DB_USER: ${{ secrets.DB_USER }}
57+
DB_USER: ${{ secrets.DB_USER || 'postgres' }}
4258
DB_PASSWORD: ${{ secrets.DB_PASSWORD }}
43-
DB_NAME: ${{ secrets.DB_NAME || 'fantasy_soccer' }}
59+
DB_NAME: ${{ secrets.DB_NAME || 'postgres' }}
4460
DB_PORT: ${{ secrets.DB_PORT || '5432' }}
4561
ELO_DATA_PATH: ../temp-elo-data/data
4662
run: |

flask-api/scripts/ingest_elo_and_fpl.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,19 @@
5050
def get_db_connection():
5151
"""Get PostgreSQL database connection"""
5252
try:
53+
# Log connection details (without password)
54+
logger.info(f"Attempting to connect to PostgreSQL: {DB_CONFIG['host']}:{DB_CONFIG['port']}/{DB_CONFIG['database']} as {DB_CONFIG['user']}")
55+
56+
if not DB_CONFIG['password']:
57+
logger.error("DB_PASSWORD environment variable is not set!")
58+
raise ValueError("DB_PASSWORD is required but not set")
59+
5360
connection = psycopg2.connect(**DB_CONFIG)
5461
logger.info("Successfully connected to PostgreSQL database")
5562
return connection
5663
except Error as e:
5764
logger.error(f"Error connecting to PostgreSQL: {e}")
65+
logger.error(f"Connection config: host={DB_CONFIG['host']}, port={DB_CONFIG['port']}, database={DB_CONFIG['database']}, user={DB_CONFIG['user']}")
5866
raise
5967

6068
def fetch_fpl_data():

0 commit comments

Comments
 (0)