feat(phase-4): Backend API for custom workouts
- Add custom_workouts and custom_workout_exercises tables (schema) - New endpoints: - GET /api/exercises - List all exercises for picker - POST /api/custom-workouts - Fork program workout - GET /api/custom-workouts - List user's custom workouts - GET /api/custom-workouts/:id - Get workout with exercises - PUT /api/custom-workouts/:id - Update workout exercises - DELETE /api/custom-workouts/:id - Delete custom workout - Updated endpoints for source_type support: - GET /api/logs - Filter by source_type and custom_workout_id - POST /api/logs - Save with source_type and custom_workout_id - DELETE /api/logs - Support custom workout log deletion - Adds Phase 4 planning overview Completes: 04-01-schema-migration, 04-02-backend-api Next: 04-03-frontend-workout-edit
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
-- Migration 004: Add custom workout support
|
||||
-- Allows users to create personalized workout plans based on program days
|
||||
|
||||
-- Custom workouts created by users
|
||||
CREATE TABLE IF NOT EXISTS custom_workouts (
|
||||
id SERIAL PRIMARY KEY,
|
||||
user_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
name VARCHAR(255) NOT NULL,
|
||||
description TEXT,
|
||||
source_program_day_id INTEGER REFERENCES program_days(id) ON DELETE SET NULL,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
-- Exercises within a custom workout
|
||||
CREATE TABLE IF NOT EXISTS custom_workout_exercises (
|
||||
id SERIAL PRIMARY KEY,
|
||||
custom_workout_id INTEGER NOT NULL REFERENCES custom_workouts(id) ON DELETE CASCADE,
|
||||
exercise_id INTEGER NOT NULL REFERENCES exercises(id) ON DELETE CASCADE,
|
||||
sets INTEGER NOT NULL DEFAULT 3,
|
||||
reps_min INTEGER NOT NULL DEFAULT 8,
|
||||
reps_max INTEGER NOT NULL DEFAULT 12,
|
||||
rpe_target DECIMAL(3,1),
|
||||
replaced_exercise_id INTEGER REFERENCES exercises(id) ON DELETE SET NULL,
|
||||
order_index INTEGER NOT NULL DEFAULT 0,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
-- Extend workout_logs to support custom workouts
|
||||
ALTER TABLE workout_logs
|
||||
ADD COLUMN IF NOT EXISTS source_type VARCHAR(20) DEFAULT 'program' CHECK (source_type IN ('program', 'custom')),
|
||||
ADD COLUMN IF NOT EXISTS custom_workout_id INTEGER REFERENCES custom_workouts(id) ON DELETE SET NULL;
|
||||
|
||||
-- Indexes
|
||||
CREATE INDEX IF NOT EXISTS idx_custom_workouts_user ON custom_workouts(user_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_custom_workout_exercises_workout ON custom_workout_exercises(custom_workout_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_workout_logs_custom_workout ON workout_logs(custom_workout_id);
|
||||
Reference in New Issue
Block a user