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
This commit is contained in:
parent
ba5d460e92
commit
029530e078
|
|
@ -201,7 +201,21 @@ def get_focus_areas(session: dict = Depends(require_auth)):
|
|||
with get_db() as conn:
|
||||
cur = get_cursor(conn)
|
||||
|
||||
# Try to get custom focus areas
|
||||
# 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,
|
||||
|
|
@ -210,8 +224,9 @@ def get_focus_areas(session: dict = Depends(require_auth)):
|
|||
WHERE profile_id = %s AND active = true
|
||||
LIMIT 1
|
||||
""", (pid,))
|
||||
|
||||
row = cur.fetchone()
|
||||
except:
|
||||
row = None
|
||||
|
||||
if row:
|
||||
return {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user