|
| 1 | +-- This file corresponds to the necessary CS340 Portfolio Project deliverables. |
| 2 | + |
| 3 | +SET foreign_key_checks = 0; |
| 4 | +SET autocommit = 0; |
| 5 | + |
| 6 | +-- Ensures clean import |
| 7 | +DROP TABLE IF EXISTS Users; |
| 8 | +DROP TABLE IF EXISTS WorkoutSessions; |
| 9 | +DROP TABLE IF EXISTS ListExercises; |
| 10 | +DROP TABLE IF EXISTS SessionExercises; |
| 11 | +DROP TABLE IF EXISTS Metrics; |
| 12 | + |
| 13 | +-- User table that stores platform users |
| 14 | +CREATE TABLE Users ( |
| 15 | + user_id INT PRIMARY KEY AUTO_INCREMENT, |
| 16 | + username VARCHAR(255) NOT NULL UNIQUE, |
| 17 | + contact VARCHAR(15) NOT NULL UNIQUE |
| 18 | +); |
| 19 | + |
| 20 | +-- Log specific workout session |
| 21 | +CREATE TABLE WorkoutSessions ( |
| 22 | + workout_session_id INT PRIMARY KEY AUTO_INCREMENT, |
| 23 | + user_id INT NOT NULL, |
| 24 | + workout_date DATETIME NOT NULL, |
| 25 | + duration_minutes INT NOT NULL, |
| 26 | + notes CHAR(255), |
| 27 | + -- Foreign key links user_id in WorkoutSessions to the primary key in Users. |
| 28 | + -- This ensures that each workout session is associated with a valid user. |
| 29 | + FOREIGN KEY (user_id) REFERENCES Users(user_id) ON DELETE CASCADE |
| 30 | +); |
| 31 | + |
| 32 | +-- Exercise table to store various exercises that can be added to a workout |
| 33 | +CREATE TABLE ListExercises ( |
| 34 | + exercise_id INT PRIMARY KEY AUTO_INCREMENT, |
| 35 | + name CHAR(255) NOT NULL, |
| 36 | + description CHAR(255), |
| 37 | + category CHAR(255) NOT NULL |
| 38 | +); |
| 39 | + |
| 40 | +-- Stores exercises performed in a specific workout |
| 41 | +CREATE TABLE SessionExercises ( |
| 42 | + session_exercise_id INT PRIMARY KEY AUTO_INCREMENT, |
| 43 | + workout_session_id INT NOT NULL, |
| 44 | + exercise_id INT NULL, |
| 45 | + sets INT NOT NULL, |
| 46 | + reps INT NOT NULL, |
| 47 | + weight INT, |
| 48 | + -- Foreign key links workout_session_id to WorkoutSessions, enforcing that each |
| 49 | + -- entry in SessionExercises is tied to an existing workout session. |
| 50 | + FOREIGN KEY (workout_session_id) REFERENCES WorkoutSessions(workout_session_id) ON DELETE CASCADE, |
| 51 | + -- Foreign key links exercise_id to ListExercises, ensuring exercises performed |
| 52 | + -- in each session are valid and listed in ListExercises. |
| 53 | + FOREIGN KEY (exercise_id) REFERENCES ListExercises(exercise_id) ON DELETE CASCADE |
| 54 | +); |
| 55 | + |
| 56 | +-- Store various metrics for a user's progress |
| 57 | +CREATE TABLE Metrics ( |
| 58 | + metric_id INT PRIMARY KEY AUTO_INCREMENT, |
| 59 | + user_id INT NOT NULL, |
| 60 | + metric_type VARCHAR(255) NOT NULL, |
| 61 | + value DECIMAL(10, 2) NOT NULL, |
| 62 | + date_recorded TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, |
| 63 | + -- Foreign key links user_id in Metrics to Users, ensuring each metric is tied |
| 64 | + -- to a valid user, so deleted users have their metrics automatically removed. |
| 65 | + FOREIGN KEY (user_id) REFERENCES Users(user_id) ON DELETE CASCADE |
| 66 | +); |
| 67 | + |
| 68 | +-- Populate Users table with sample data |
| 69 | +INSERT INTO Users (username, contact) |
| 70 | +VALUES |
| 71 | + ('kangjoo', 1234567890), |
| 72 | + ('hinsonj', 1234567891), |
| 73 | + ('tanalexis', 1234567892); |
| 74 | + |
| 75 | +-- Populate WorkoutSessions table with sample data |
| 76 | +INSERT INTO WorkoutSessions (user_id, workout_date, duration_minutes, notes) |
| 77 | +VALUES |
| 78 | + ((SELECT user_id FROM Users WHERE username = 'kangjoo'), '2024-11-01 08:00:00', 60, 'Morning workout, low intensity, form focused'), |
| 79 | + ((SELECT user_id FROM Users WHERE username = 'hinsonj'), '2024-11-02 09:00:00', 45, NULL), |
| 80 | + ((SELECT user_id FROM Users WHERE username = 'tanalexis'), '2024-11-03 12:00:00', 30, 'Quick session, high intensity'); |
| 81 | + |
| 82 | +-- Populate ListExercises table with sample data |
| 83 | +INSERT INTO ListExercises (name, description, category) |
| 84 | +VALUES |
| 85 | + ('Push Up', 'https://www.youtube.com/watch?v=IODxDxX7oi4', 'Strength'), |
| 86 | + ('Squat', 'https://www.youtube.com/watch?v=byxWus7BwfQ', 'Strength'), |
| 87 | + ('Running', 'https://www.youtube.com/watch?v=brFHyOtTwH4', 'Cardio'); |
| 88 | + |
| 89 | +-- Populate SessionExercises table with sample data |
| 90 | +INSERT INTO SessionExercises (workout_session_id, exercise_id, sets, reps, weight) |
| 91 | +VALUES |
| 92 | + ((SELECT workout_session_id FROM WorkoutSessions WHERE notes LIKE '%Morning workout%'), |
| 93 | + (SELECT exercise_id FROM ListExercises WHERE name = 'Push Up'), 3, 25, NULL), |
| 94 | + ((SELECT workout_session_id FROM WorkoutSessions WHERE notes LIKE '%Quick session%'), |
| 95 | + (SELECT exercise_id FROM ListExercises WHERE name = 'Running'), 1, 0, NULL), |
| 96 | + ((SELECT workout_session_id FROM WorkoutSessions WHERE notes IS NULL), |
| 97 | + (SELECT exercise_id FROM ListExercises WHERE name = 'Squat'), 4, 10, 250); |
| 98 | + |
| 99 | +-- Populate Metrics table with sample data |
| 100 | +INSERT INTO Metrics (user_id, metric_type, value, date_recorded) |
| 101 | +VALUES |
| 102 | + ((SELECT user_id FROM Users WHERE username = 'kangjoo'), 'Body Weight', 180.5, '2024-01-05 08:00:00'), |
| 103 | + ((SELECT user_id FROM Users WHERE username = 'hinsonj'), 'Personal Best', 200.0, '2024-01-05 08:00:00'), |
| 104 | + ((SELECT user_id FROM Users WHERE username = 'tanalexis'), 'Body Weight', 150.5, '2024-01-06 08:00:00'); |
| 105 | + |
| 106 | +SET foreign_key_checks = 1; |
| 107 | +set autocommit = 1; |
| 108 | + |
| 109 | +COMMIT; |
0 commit comments