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 {