-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
108 lines (95 loc) · 3.19 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import sqlite3
# # Connect to the SQLite database (or create it)
# conn = sqlite3.connect("workouts.db")
# cursor = conn.cursor()
# # Create the Exercises table
# cursor.execute(
# """
# CREATE TABLE IF NOT EXISTS Exercises (
# exercise_id INTEGER PRIMARY KEY AUTOINCREMENT,
# name TEXT NOT NULL,
# description TEXT,
# created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
# )
# """
# )
# # Create the Workout Templates table
# cursor.execute(
# """
# CREATE TABLE IF NOT EXISTS WorkoutTemplates (
# template_id INTEGER PRIMARY KEY AUTOINCREMENT,
# template_name TEXT NOT NULL,
# created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
# )
# """
# )
# # Create the Workout Template Exercises table (junction table)
# cursor.execute(
# """
# CREATE TABLE IF NOT EXISTS WorkoutTemplateExercises (
# template_id INTEGER,
# exercise_id INTEGER,
# default_reps INTEGER,
# default_sets INTEGER,
# default_weight INTEGER,
# created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
# FOREIGN KEY (template_id) REFERENCES WorkoutTemplates(template_id),
# FOREIGN KEY (exercise_id) REFERENCES Exercises(exercise_id)
# )
# """
# )
# # Create the Workouts table
# cursor.execute(
# """
# CREATE TABLE IF NOT EXISTS Workouts (
# workout_id INTEGER PRIMARY KEY AUTOINCREMENT,
# template_id INTEGER,
# workout_date DATE,
# notes TEXT,
# created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
# FOREIGN KEY (template_id) REFERENCES WorkoutTemplates(template_id)
# )
# """
# )
# # Create the Workout Entries table
# cursor.execute(
# """
# CREATE TABLE IF NOT EXISTS WorkoutEntries (
# workout_entry_id INTEGER PRIMARY KEY AUTOINCREMENT,
# workout_id INTEGER,
# exercise_id INTEGER,
# custom_reps INTEGER,
# custom_sets INTEGER,
# custom_weight INTEGER,
# created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
# FOREIGN KEY (workout_id) REFERENCES Workouts(workout_id),
# FOREIGN KEY (exercise_id) REFERENCES Exercises(exercise_id)
# )
# """
# )
# # Commit the changes and close the connection
# conn.commit()
# conn.close()
# print("Database and tables created successfully.")
# Insert sample data into Exercises and WorkoutTemplates
conn = sqlite3.connect("workouts.db")
cursor = conn.cursor()
cursor.execute(
"INSERT INTO Exercises (name, description) VALUES ('Push-up', 'A basic bodyweight exercise')"
)
cursor.execute(
"INSERT INTO Exercises (name, description) VALUES ('Squat', 'A basic leg exercise')"
)
cursor.execute(
"INSERT INTO WorkoutTemplates (template_name) VALUES ('Beginner Full Body')"
)
# Insert data into WorkoutTemplateExercises (associate exercises with a template)
cursor.execute(
"INSERT INTO WorkoutTemplateExercises (template_id, exercise_id, default_reps, default_sets, default_weight) VALUES (1, 1, 10, 3, NULL)"
) # Push-up
cursor.execute(
"INSERT INTO WorkoutTemplateExercises (template_id, exercise_id, default_reps, default_sets, default_weight) VALUES (1, 2, 15, 3, NULL)"
) # Squat
conn.commit()
conn.close()
print("Sample data inserted successfully.")