fix: Graceful fallback if Migration 031 not yet applied
- Wrap focus_contributions loading in try/catch - If tables don't exist (migration not run), continue without them - Backward compatible with pre-migration state - Logs warning but doesn't crash
This commit is contained in:
parent
34ea51b8bd
commit
ba5d460e92
|
|
@ -720,29 +720,34 @@ def get_goals_grouped(session: dict = Depends(require_auth)):
|
|||
focus_map = {} # goal_id → [contributions]
|
||||
|
||||
if goal_ids:
|
||||
placeholders = ','.join(['%s'] * len(goal_ids))
|
||||
cur.execute(f"""
|
||||
SELECT
|
||||
gfc.goal_id, gfc.contribution_weight,
|
||||
fa.id as focus_area_id, fa.key, fa.name_de, fa.icon, fa.category
|
||||
FROM goal_focus_contributions gfc
|
||||
JOIN focus_area_definitions fa ON gfc.focus_area_id = fa.id
|
||||
WHERE gfc.goal_id IN ({placeholders})
|
||||
ORDER BY gfc.contribution_weight DESC
|
||||
""", tuple(goal_ids))
|
||||
try:
|
||||
placeholders = ','.join(['%s'] * len(goal_ids))
|
||||
cur.execute(f"""
|
||||
SELECT
|
||||
gfc.goal_id, gfc.contribution_weight,
|
||||
fa.id as focus_area_id, fa.key, fa.name_de, fa.icon, fa.category
|
||||
FROM goal_focus_contributions gfc
|
||||
JOIN focus_area_definitions fa ON gfc.focus_area_id = fa.id
|
||||
WHERE gfc.goal_id IN ({placeholders})
|
||||
ORDER BY gfc.contribution_weight DESC
|
||||
""", tuple(goal_ids))
|
||||
|
||||
for row in cur.fetchall():
|
||||
gid = row['goal_id']
|
||||
if gid not in focus_map:
|
||||
focus_map[gid] = []
|
||||
focus_map[gid].append({
|
||||
'focus_area_id': row['focus_area_id'],
|
||||
'key': row['key'],
|
||||
'name_de': row['name_de'],
|
||||
'icon': row['icon'],
|
||||
'category': row['category'],
|
||||
'contribution_weight': float(row['contribution_weight'])
|
||||
})
|
||||
for row in cur.fetchall():
|
||||
gid = row['goal_id']
|
||||
if gid not in focus_map:
|
||||
focus_map[gid] = []
|
||||
focus_map[gid].append({
|
||||
'focus_area_id': row['focus_area_id'],
|
||||
'key': row['key'],
|
||||
'name_de': row['name_de'],
|
||||
'icon': row['icon'],
|
||||
'category': row['category'],
|
||||
'contribution_weight': float(row['contribution_weight'])
|
||||
})
|
||||
except Exception as e:
|
||||
# Migration 031 not yet applied - focus_contributions tables don't exist
|
||||
print(f"[WARNING] Could not load focus_contributions: {e}")
|
||||
# Continue without focus_contributions (backward compatible)
|
||||
|
||||
# Group by category and attach focus_contributions
|
||||
grouped = {}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user