From 029530e07800f6f71275e3237cd78faf519fdb40 Mon Sep 17 00:00:00 2001 From: Lars Date: Fri, 27 Mar 2026 20:34:06 +0100 Subject: [PATCH] fix: backward compatibility for focus_areas migration - get_focus_areas now tries user_focus_preferences first (Migration 031) - Falls back to old focus_areas table if Migration 031 not applied - get_goals_grouped wraps focus_contributions loading in try/catch - Graceful degradation until migrations run --- backend/routers/goals.py | 37 ++++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/backend/routers/goals.py b/backend/routers/goals.py index 7604b1e..3b0a529 100644 --- a/backend/routers/goals.py +++ b/backend/routers/goals.py @@ -201,17 +201,32 @@ def get_focus_areas(session: dict = Depends(require_auth)): with get_db() as conn: cur = get_cursor(conn) - # Try to get custom focus areas - cur.execute(""" - SELECT weight_loss_pct, muscle_gain_pct, strength_pct, - endurance_pct, flexibility_pct, health_pct, - created_at, updated_at - FROM focus_areas - WHERE profile_id = %s AND active = true - LIMIT 1 - """, (pid,)) - - row = cur.fetchone() + # Try to get custom focus areas (user_focus_preferences after Migration 031) + try: + cur.execute(""" + SELECT weight_loss_pct, muscle_gain_pct, strength_pct, + endurance_pct, flexibility_pct, health_pct, + created_at, updated_at + FROM user_focus_preferences + WHERE profile_id = %s + LIMIT 1 + """, (pid,)) + row = cur.fetchone() + except Exception as e: + # Migration 031 not applied yet, try old table name + print(f"[WARNING] user_focus_preferences not found, trying old focus_areas: {e}") + try: + cur.execute(""" + SELECT weight_loss_pct, muscle_gain_pct, strength_pct, + endurance_pct, flexibility_pct, health_pct, + created_at, updated_at + FROM focus_areas + WHERE profile_id = %s AND active = true + LIMIT 1 + """, (pid,)) + row = cur.fetchone() + except: + row = None if row: return {