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