LogicAndPhysicalDeisgn: kreiranje.sql

File kreiranje.sql, 3.5 KB (added by 201136, 9 months ago)
Line 
1set search_path = project;
2
3
4drop table if exists UserHasProgram;
5drop table if exists UserHasDay;
6drop table if exists DayHasMeal;
7drop table if exists MealHasIngredient;
8drop table if exists DayHasWorkout;
9drop table if exists WorkoutHasExercise;
10drop table if exists WorkoutProgramHasWorkout;
11
12
13drop table if exists _User;
14drop table if exists _Day;
15drop table if exists Meal;
16drop table if exists Ingredient;
17drop table if exists PersonalizedIngredient;
18drop table if exists Workout;
19drop table if exists Exercise;
20drop table if exists PersonalizedExercise;
21drop table if exists WorkoutProgram;
22
23
24
25drop domain if exists string_dolg;
26drop domain if exists string_kratok;
27
28
29drop schema if exists project;
30
31create schema project;
32
33set search_path = project;
34
35
36create domain string_dolg AS character varying(4000);
37create domain string_kratok AS character varying(500);
38
39
40create 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
50create table _Day (
51 dID bigint primary key,
52 date date not null
53);
54
55create 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
63create 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
71create 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
80create table PersonalizedIngredient (
81 piID bigint primary key,
82 quantity integer not null,
83 iID bigint,
84 foreign key (iID) references Ingredient(iID)
85);
86
87create table Exercise (
88 eID bigint primary key,
89 name string_kratok not null,
90 type string_kratok not null
91);
92create 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
102create table WorkoutProgram (
103 wpID bigint primary key,
104 name string_kratok not null
105);
106
107
108
109create table UserHasDay(
110 uID bigint references _User(uID),
111 dID bigint references _Day(dID),
112
113 constraint UserHasDay_pkey primary key (dID)
114);
115
116create table UserHasProgram(
117 uID bigint references _User(uID),
118 wpID bigint references WorkoutProgram(wpID),
119
120 constraint UserHasProgram_pkey primary key (wpID)
121);
122
123create 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
130create 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
137create 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
145create 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
152create 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