| Prompt | this is a lot
Step 1:
Add two columns to the exercises table:
external_id (VARCHAR(100), UNIQUE, nullable) — will store the stable id field from the source exercise JSON (e.g., "Air_Bike") for pre-built exercises. Custom exercises will have external_id = NULL.
image_urls (JSON, nullable) — will store an array of image URLs per exercise. Custom exercises will have image_urls = NULL.
Don't populate these yet — just add the columns and confirm the migration runs cleanly against the existing table.
Step 2: Before making any changes, check whether any pre-built exercises (is_custom = false) are currently referenced by rows in plan_exercises or session_exercise_logs. Report which exercises (if any) are referenced, and by how many rows, so I can decide whether a full delete-and-reinsert is safe.
Step 3: Delete all rows in exercises where is_custom = false. If the foreign key constraints from plan_exercises or session_exercise_logsblock any deletions, stop immediately and report exactly which rows are blocking it, rather than partially deleting data.
Step 4:
Fetch the exercise list from https://raw.githubusercontent.com/yuhonas/free-exercise-db/main/dist/exercises.json and insert it into exercises, mapping fields as follows:
name → name
category → exercise_type (strength/powerlifting/strongman/olympic weightlifting/plyometrics → 'strength', cardio → 'cardio', stretching → 'mobility')
primaryMuscles[0] → primary_muscle, normalized to the existing ENUM (chest, back, shoulders, biceps, triceps, forearms, abs, quads, hamstrings, glutes, calves, full_body); use 'full_body' as fallback for anything unmapped
equipment → equipment as-is
instructions array joined into description
images array → image_urls, with each relative path prepended with https://raw.githubusercontent.com/yuhonas/free-exercise-db/main/exercises/ to form full URLs
id (source field) → external_id
is_custom = false, created_by = NULL
Report the total number of exercises inserted, and separately list any rows that failed the primary_muscle ENUM mapping.
Step 5: Show me 5 random exercises from the exercises table including their name, primary_muscle, external_id, and image_urls, so I can manually verify the mapping and image URLs look correct.
|
|---|