I am creating a workout app using MySQL and Prisma, and I am struggling to design a schema for the data.
The app will have users and workout programs. For example a workout program 'Get Jacked', could consist of 3 blocks (each block is 1 month). Each block will contain 5 workouts per week, each workout will contain multiple exercises and a warm up. Some important things to note: each User should be able to record their personal sets and reps for each exercise within a workout. They should also be able to complete a program ('Get Jacked'), as many times as they like and each time they should be able to record new values for their reps and sets.
Here's my models so far:
model User {
id Int @id @default(autoincrement())
email String @unique
name String?
role Role @default(USER)
workouts Workout[]
}
model Program {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
name String
published Boolean @default(false)
author User @relation(fields: [authorId], references: [id])
authorId Int
}
model Block {
id Int @id @default(autoincrement())
name String
program Program @relation(fields: [programId], references: [id])
programId Int
}
model Workout {
id Int @id @default(autoincrement())
name String
week String
day String
block Block @relation(fields: [blockId], references: [id])
blockId Int
}
model WorkoutSet {
id Int @id @default(autoincrement())
name String
sets Int
reps Int
workout Workout @relation(fields: [workoutId], references: [id])
workoutId Int
exercise Exercise @relation(fields: [exerciseId], references: [id])
exerciseId Int
}
model Exercise {
id Int @id @default(autoincrement())
name String
}
model LogWorkout {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
workout Workout @relation(fields: [workoutId], references: [id])
workoutId Int
}
model LogWorkoutSet {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
sets Int
reps Int
weight Int
logWorkout LogWorkout @relation(fields: [logWorkoutId], references: [id])
logWorkoutId Int
workoutSet User @relation(fields: [workoutSetId], references: [id])
workoutSetId Int
}
I am relatively new to relational databases and what I can't seem to get my head around is how the recording of the reps ties back to the user and how the user can complete the workout program multiple times.
Any help would be much appreciated.
Thanks, Adam