1 | set search_path = project;
|
---|
2 |
|
---|
3 | drop table if exists se_naogja2;
|
---|
4 | drop table if exists se_naogja1;
|
---|
5 | drop table if exists ja_ima;
|
---|
6 | drop table if exists so_koi;
|
---|
7 | drop table if exists opsluzuva;
|
---|
8 | drop table if exists od_kade;
|
---|
9 | drop table if exists sodrzi;
|
---|
10 | drop table if exists pripagja;
|
---|
11 | drop table if exists zadolzen_za;
|
---|
12 |
|
---|
13 | drop table if exists komentari;
|
---|
14 | drop table if exists naracki;
|
---|
15 | drop table if exists sliki;
|
---|
16 | drop table if exists posetiteli;
|
---|
17 | drop table if exists vraboteni;
|
---|
18 | drop table if exists korisnici;
|
---|
19 | drop table if exists restorani;
|
---|
20 | drop table if exists lokacii;
|
---|
21 | drop table if exists prodavnici;
|
---|
22 | drop table if exists recepti;
|
---|
23 | drop table if exists potekla;
|
---|
24 | drop table if exists sostojki;
|
---|
25 | drop table if exists kategorii;
|
---|
26 |
|
---|
27 | drop schema if exists project;
|
---|
28 |
|
---|
29 | create schema project;
|
---|
30 |
|
---|
31 | set search_path = project;
|
---|
32 |
|
---|
33 | create table kategorii(
|
---|
34 | kat_id integer,
|
---|
35 | kat_ime varchar(400) unique not null,
|
---|
36 | opis varchar(2000),
|
---|
37 |
|
---|
38 | constraint pk_kategorii primary key (kat_id)
|
---|
39 | );
|
---|
40 |
|
---|
41 | create table sostojki(
|
---|
42 | s_id integer,
|
---|
43 | s_naziv varchar(400) unique not null,
|
---|
44 |
|
---|
45 | constraint pk_sostojki primary key(s_id)
|
---|
46 | );
|
---|
47 |
|
---|
48 | create table potekla(
|
---|
49 | pot_id integer,
|
---|
50 | pot_naziv varchar(400) unique not null,
|
---|
51 |
|
---|
52 | constraint pk_potekla primary key(pot_id)
|
---|
53 | );
|
---|
54 | --added rec_ime
|
---|
55 | create table recepti(
|
---|
56 | rec_id bigint,
|
---|
57 | postapka varchar(4000),
|
---|
58 | rec_ime varchar(200),
|
---|
59 |
|
---|
60 | constraint pk_recepti primary key (rec_id)
|
---|
61 | );
|
---|
62 |
|
---|
63 | create table prodavnici(
|
---|
64 | pro_id integer,
|
---|
65 | pro_naziv varchar(200),
|
---|
66 |
|
---|
67 | constraint pk_prodavnici primary key (pro_id)
|
---|
68 | );
|
---|
69 |
|
---|
70 | create table lokacii(
|
---|
71 | l_id integer,
|
---|
72 | adresa varchar(300) not null,
|
---|
73 |
|
---|
74 | constraint pk_lokacii primary key (l_id)
|
---|
75 | );
|
---|
76 |
|
---|
77 | create table restorani(
|
---|
78 | res_id integer,
|
---|
79 | res_naziv varchar(200),
|
---|
80 |
|
---|
81 | constraint pk_restorani primary key (res_id)
|
---|
82 | );
|
---|
83 |
|
---|
84 | create table korisnici(
|
---|
85 | telefon char(9),
|
---|
86 | kor_ime varchar(200) not null,
|
---|
87 | prezime varchar(400),
|
---|
88 |
|
---|
89 | constraint pk_korisnici primary key (telefon)
|
---|
90 | );
|
---|
91 |
|
---|
92 | create table vraboteni(
|
---|
93 | telefon char(9),
|
---|
94 |
|
---|
95 | constraint pk_vraboteni primary key (telefon),
|
---|
96 | constraint fk_vraboteni foreign key (telefon) references korisnici(telefon)
|
---|
97 | );
|
---|
98 |
|
---|
99 | create table posetiteli(
|
---|
100 | telefon char(9),
|
---|
101 |
|
---|
102 | constraint pk_posetiteli primary key (telefon),
|
---|
103 | constraint fk_posetiteli foreign key (telefon) references korisnici(telefon)
|
---|
104 | );
|
---|
105 |
|
---|
106 | create table sliki(
|
---|
107 | reden_broj integer,
|
---|
108 | rec_id bigint,
|
---|
109 | slika bytea not null,
|
---|
110 |
|
---|
111 | constraint pk_sliki primary key (reden_broj, rec_id),
|
---|
112 | constraint fk_sliki foreign key (rec_id) references recepti(rec_id)
|
---|
113 | );
|
---|
114 |
|
---|
115 | --vreme, n_data -> vreme
|
---|
116 | create table naracki(
|
---|
117 | vreme timestamp,
|
---|
118 | telefon char(9),
|
---|
119 |
|
---|
120 | constraint pk_naracki primary key (vreme, telefon),
|
---|
121 | constraint fk_naracki foreign key (telefon) references posetiteli(telefon)
|
---|
122 | );
|
---|
123 |
|
---|
124 | create table komentari(
|
---|
125 | kom_data timestamp,
|
---|
126 | telefon char(9),
|
---|
127 | rec_id bigint,
|
---|
128 | ocena smallint not null,
|
---|
129 | text varchar(2000),
|
---|
130 |
|
---|
131 | constraint pk_komentari primary key(kom_data, telefon, rec_id),
|
---|
132 | constraint fk_komentari_telefon foreign key (telefon) references posetiteli(telefon),
|
---|
133 | constraint fk_komentari_rec_id foreign key (rec_id) references recepti(rec_id),
|
---|
134 | constraint in_range_ocena check(ocena >= 1 and ocena <= 10)
|
---|
135 | );
|
---|
136 |
|
---|
137 | --relacii
|
---|
138 |
|
---|
139 | create table zadolzen_za(
|
---|
140 | v_telefon char(9),
|
---|
141 | vreme timestamp,
|
---|
142 | p_telefon char(9),
|
---|
143 |
|
---|
144 | constraint pk_zadolzen_za primary key (v_telefon, vreme, p_telefon),
|
---|
145 | constraint fk_zadolzen_za_v_telefon foreign key (v_telefon) references vraboteni(telefon),
|
---|
146 | constraint fk_zadlozen_za_n_vreme foreign key (vreme, p_telefon) references naracki(vreme, telefon)
|
---|
147 | );
|
---|
148 |
|
---|
149 | create table pripagja(
|
---|
150 | kat_id integer,
|
---|
151 | rec_id bigint,
|
---|
152 | constraint pk_pripagja primary key (kat_id, rec_id),
|
---|
153 | constraint fk_pripagja_kat foreign key (kat_id) references kategorii(kat_id),
|
---|
154 | constraint fk_pripagja_rec foreign key (rec_id) references recepti(rec_id)
|
---|
155 | );
|
---|
156 |
|
---|
157 | create table sodrzi(
|
---|
158 | s_id integer,
|
---|
159 | rec_id bigint,
|
---|
160 | constraint pk_sodrzi primary key (s_id, rec_id),
|
---|
161 | constraint fk_sodrzi_s_id foreign key (s_id) references sostojki(s_id),
|
---|
162 | constraint fk_sodrzi_rec_id foreign key (rec_id) references recepti(rec_id)
|
---|
163 | );
|
---|
164 |
|
---|
165 |
|
---|
166 | create table od_kade(
|
---|
167 | pot_id integer,
|
---|
168 | rec_id bigint,
|
---|
169 | constraint pk_od_kade primary key (pot_id, rec_id),
|
---|
170 | constraint fk_od_kade_pot_id foreign key (pot_id) references potekla(pot_id),
|
---|
171 | constraint fk_od_kade_rec_id foreign key (rec_id) references recepti(rec_id)
|
---|
172 | );
|
---|
173 |
|
---|
174 |
|
---|
175 | create table opsluzuva(
|
---|
176 | res_id integer,
|
---|
177 | rec_id bigint,
|
---|
178 | constraint pk_opsluzuva primary key (res_id, rec_id),
|
---|
179 | constraint rec_id_not_unique unique (rec_id),
|
---|
180 | constraint fk_opsluzuva_res_id foreign key (res_id) references restorani(res_id),
|
---|
181 | constraint fk_opsluzuva_rec_id foreign key (rec_id) references recepti(rec_id)
|
---|
182 | );
|
---|
183 |
|
---|
184 | create table so_koi(
|
---|
185 | vreme timestamp,
|
---|
186 | telefon char(9),
|
---|
187 | rec_id bigint,
|
---|
188 | nacin varchar(20),
|
---|
189 | constraint pk_so_koi primary key (vreme, telefon, rec_id),
|
---|
190 | constraint fk_so_koi_naracki foreign key (vreme, telefon) references naracki(vreme, telefon),
|
---|
191 | constraint fk_opsluzuva_rec_id foreign key (rec_id) references recepti(rec_id)
|
---|
192 | );
|
---|
193 |
|
---|
194 | create table ja_ima(
|
---|
195 | s_id integer,
|
---|
196 | pro_id integer,
|
---|
197 | kolicina varchar(50),
|
---|
198 | cena integer,
|
---|
199 | constraint pk_ja_ima primary key (s_id, pro_id),
|
---|
200 | constraint fk_ja_ima_sostojki foreign key (s_id) references sostojki(s_id),
|
---|
201 | constraint fk_ja_ima_pro foreign key (pro_id) references prodavnici(pro_id)
|
---|
202 | );
|
---|
203 |
|
---|
204 | create table se_naogja1(
|
---|
205 | res_id integer,
|
---|
206 | l_id integer,
|
---|
207 | constraint pk_se_naogja1 primary key (res_id, l_id),
|
---|
208 | constraint fk_se_naogja1_l_id foreign key (l_id) references lokacii(l_id),
|
---|
209 | constraint fk_se_naogja1_res_id foreign key (res_id) references restorani(res_id)
|
---|
210 | );
|
---|
211 |
|
---|
212 | create table se_naogja2(
|
---|
213 | pro_id integer,
|
---|
214 | l_id integer,
|
---|
215 | constraint pk_se_naogja2 primary key (pro_id, l_id),
|
---|
216 | constraint fk_se_naogja2_l_id foreign key (l_id) references lokacii(l_id),
|
---|
217 | constraint fk_se_naogja2_pro_id foreign key (pro_id) references prodavnici(pro_id)
|
---|
218 | );
|
---|
219 |
|
---|
220 |
|
---|
221 |
|
---|
222 |
|
---|
223 |
|
---|
224 |
|
---|