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]
|
focus_map = {} # goal_id → [contributions]
|
||||||
|
|
||||||
if goal_ids:
|
if goal_ids:
|
||||||
placeholders = ','.join(['%s'] * len(goal_ids))
|
try:
|
||||||
cur.execute(f"""
|
placeholders = ','.join(['%s'] * len(goal_ids))
|
||||||
SELECT
|
cur.execute(f"""
|
||||||
gfc.goal_id, gfc.contribution_weight,
|
SELECT
|
||||||
fa.id as focus_area_id, fa.key, fa.name_de, fa.icon, fa.category
|
gfc.goal_id, gfc.contribution_weight,
|
||||||
FROM goal_focus_contributions gfc
|
fa.id as focus_area_id, fa.key, fa.name_de, fa.icon, fa.category
|
||||||
JOIN focus_area_definitions fa ON gfc.focus_area_id = fa.id
|
FROM goal_focus_contributions gfc
|
||||||
WHERE gfc.goal_id IN ({placeholders})
|
JOIN focus_area_definitions fa ON gfc.focus_area_id = fa.id
|
||||||
ORDER BY gfc.contribution_weight DESC
|
WHERE gfc.goal_id IN ({placeholders})
|
||||||
""", tuple(goal_ids))
|
ORDER BY gfc.contribution_weight DESC
|
||||||
|
""", tuple(goal_ids))
|
||||||
|
|
||||||
for row in cur.fetchall():
|
for row in cur.fetchall():
|
||||||
gid = row['goal_id']
|
gid = row['goal_id']
|
||||||
if gid not in focus_map:
|
if gid not in focus_map:
|
||||||
focus_map[gid] = []
|
focus_map[gid] = []
|
||||||
focus_map[gid].append({
|
focus_map[gid].append({
|
||||||
'focus_area_id': row['focus_area_id'],
|
'focus_area_id': row['focus_area_id'],
|
||||||
'key': row['key'],
|
'key': row['key'],
|
||||||
'name_de': row['name_de'],
|
'name_de': row['name_de'],
|
||||||
'icon': row['icon'],
|
'icon': row['icon'],
|
||||||
'category': row['category'],
|
'category': row['category'],
|
||||||
'contribution_weight': float(row['contribution_weight'])
|
'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
|
# Group by category and attach focus_contributions
|
||||||
grouped = {}
|
grouped = {}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user