1 | set search_path = project;
|
---|
2 |
|
---|
3 |
|
---|
4 | drop table if exists UserHasProgram;
|
---|
5 | drop table if exists UserHasDays;
|
---|
6 | drop table if exists DayHasMeal;
|
---|
7 | drop table if exists MealHasIngredient;
|
---|
8 | drop table if exists DayHasWorkout;
|
---|
9 | drop table if exists WorkoutHasExercise;
|
---|
10 | drop table if exists WorkoutProgramHasWorkout;
|
---|
11 |
|
---|
12 |
|
---|
13 | drop table if exists Meal;
|
---|
14 | drop table if exists Workout;
|
---|
15 | drop table if exists _Day cascade;
|
---|
16 | drop table if exists _User cascade;
|
---|
17 | drop table if exists PersonalizedIngredient;
|
---|
18 | drop table if exists Ingredient;
|
---|
19 | drop table if exists PersonalizedExercise;
|
---|
20 | drop table if exists Exercise;
|
---|
21 | drop table if exists WorkoutProgram;
|
---|
22 |
|
---|
23 |
|
---|
24 |
|
---|
25 | drop schema if exists project cascade;
|
---|
26 |
|
---|
27 | create schema project;
|
---|
28 |
|
---|
29 | set search_path = project;
|
---|
30 |
|
---|
31 |
|
---|
32 |
|
---|
33 | create table _User (
|
---|
34 | uID bigint primary key,
|
---|
35 | name VARCHAR(255) not null unique,
|
---|
36 | password VARCHAR(255) not null,
|
---|
37 | age integer not null,
|
---|
38 | height integer,
|
---|
39 | weight integer,
|
---|
40 | role VARCHAR(255)
|
---|
41 | );
|
---|
42 |
|
---|
43 | create table _Day (
|
---|
44 | dID bigint primary key,
|
---|
45 | date date not null
|
---|
46 | );
|
---|
47 |
|
---|
48 | create table Workout (
|
---|
49 | wID bigint primary key,
|
---|
50 | duration integer,
|
---|
51 | name VARCHAR(255),
|
---|
52 | uID BIGINT,
|
---|
53 | foreign key (uID) references _User(uID)
|
---|
54 | );
|
---|
55 |
|
---|
56 | create table Meal (
|
---|
57 | mID bigint primary key,
|
---|
58 | name VARCHAR(255) not null,
|
---|
59 | type VARCHAR(255) not null,
|
---|
60 | uID BIGINT,
|
---|
61 | foreign key (uID) references _User(uID)
|
---|
62 | );
|
---|
63 |
|
---|
64 | create table Ingredient (
|
---|
65 | iID bigint primary key,
|
---|
66 | name VARCHAR(255) not null,
|
---|
67 | calories integer not null,
|
---|
68 | protein integer not null,
|
---|
69 | carbs integer not null,
|
---|
70 | fats integer not null
|
---|
71 | );
|
---|
72 |
|
---|
73 | create table PersonalizedIngredient (
|
---|
74 | piID bigint primary key,
|
---|
75 | quantity integer not null,
|
---|
76 | iID bigint,
|
---|
77 | foreign key (iID) references Ingredient(iID)
|
---|
78 | );
|
---|
79 |
|
---|
80 | create table Exercise (
|
---|
81 | eID bigint primary key,
|
---|
82 | name VARCHAR(255) not null,
|
---|
83 | type VARCHAR(255) not null
|
---|
84 | );
|
---|
85 | create table PersonalizedExercise (
|
---|
86 | peID bigint primary key,
|
---|
87 | reps integer,
|
---|
88 | sets integer,
|
---|
89 | weight integer,
|
---|
90 | time integer,
|
---|
91 | eID bigint,
|
---|
92 | foreign key (eID) references Exercise(eID)
|
---|
93 | );
|
---|
94 |
|
---|
95 | create table WorkoutProgram (
|
---|
96 | wpID bigint primary key,
|
---|
97 | name VARCHAR(255) not null
|
---|
98 | );
|
---|
99 |
|
---|
100 |
|
---|
101 |
|
---|
102 | create table UserHasDays(
|
---|
103 | uID bigint references _User(uID),
|
---|
104 | dID bigint references _Day(dID),
|
---|
105 |
|
---|
106 | constraint UserHasDays_pkey primary key (dID, uID)
|
---|
107 | );
|
---|
108 |
|
---|
109 | create table UserHasProgram(
|
---|
110 | uID bigint references _User(uID),
|
---|
111 | wpID bigint references WorkoutProgram(wpID),
|
---|
112 |
|
---|
113 | constraint UserHasProgram_pkey primary key (wpID, uID)
|
---|
114 | );
|
---|
115 |
|
---|
116 | create table DayHasWorkout(
|
---|
117 | wID bigint references Workout(wID),
|
---|
118 | dID bigint references _Day(dID),
|
---|
119 |
|
---|
120 | constraint DayHasWorkout_pkey primary key (wID, dID)
|
---|
121 | );
|
---|
122 |
|
---|
123 | create table WorkoutProgramHasWorkout(
|
---|
124 | wID bigint references Workout(wID),
|
---|
125 | wpID bigint references WorkoutProgram(wpID),
|
---|
126 |
|
---|
127 | constraint WorkoutProgramHasWorkout_pkey primary key (wpID, wID)
|
---|
128 | );
|
---|
129 |
|
---|
130 | create table DayHasMeal(
|
---|
131 | mID bigint references Meal(mID),
|
---|
132 | dID bigint references _Day(dID),
|
---|
133 |
|
---|
134 | constraint DayHasMeal_pkey primary key (dID, mID)
|
---|
135 | );
|
---|
136 |
|
---|
137 |
|
---|
138 | create table MealHasIngredient(
|
---|
139 | mID bigint references Meal(mID),
|
---|
140 | piID bigint references PersonalizedIngredient(piID),
|
---|
141 |
|
---|
142 | constraint MealHasIngredient_pkey primary key (piID, mID)
|
---|
143 | );
|
---|
144 |
|
---|
145 | create table WorkoutHasExercise(
|
---|
146 | peID bigint references PersonalizedExercise(peID),
|
---|
147 | wID bigint references Workout(wID),
|
---|
148 |
|
---|
149 | constraint WorkoutHasExercise_pkey primary key (peID, wID)
|
---|
150 | );
|
---|
151 |
|
---|
152 | CREATE SEQUENCE _user_seq START 1;
|
---|
153 | CREATE SEQUENCE _day_seq START 1;
|
---|
154 | CREATE SEQUENCE _workout_seq START 1;
|
---|
155 | CREATE SEQUENCE _meal_seq START 1;
|
---|
156 | CREATE SEQUENCE _ingredient_seq START 1;
|
---|
157 | CREATE SEQUENCE _personalized_ingredient_seq START 1;
|
---|
158 | CREATE SEQUENCE _exercise_seq START 1;
|
---|
159 | CREATE SEQUENCE _personalized_exercise_seq START 1;
|
---|
160 | CREATE SEQUENCE _workout_program_seq START 1;
|
---|
161 |
|
---|
162 |
|
---|