fix: backward compatibility for focus_areas migration
All checks were successful
Deploy Development / deploy (push) Successful in 51s
Build Test / lint-backend (push) Successful in 0s
Build Test / build-frontend (push) Successful in 13s

- 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
This commit is contained in:
Lars 2026-03-27 20:34:06 +01:00
parent ba5d460e92
commit 029530e078

View File

@ -201,17 +201,32 @@ def get_focus_areas(session: dict = Depends(require_auth)):
with get_db() as conn: with get_db() as conn:
cur = get_cursor(conn) cur = get_cursor(conn)
# Try to get custom focus areas # Try to get custom focus areas (user_focus_preferences after Migration 031)
cur.execute(""" try:
SELECT weight_loss_pct, muscle_gain_pct, strength_pct, cur.execute("""
endurance_pct, flexibility_pct, health_pct, SELECT weight_loss_pct, muscle_gain_pct, strength_pct,
created_at, updated_at endurance_pct, flexibility_pct, health_pct,
FROM focus_areas created_at, updated_at
WHERE profile_id = %s AND active = true FROM user_focus_preferences
LIMIT 1 WHERE profile_id = %s
""", (pid,)) LIMIT 1
""", (pid,))
row = cur.fetchone() 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: if row:
return { return {